Skip to content

Commit

Permalink
Fix "This Session's transaction has been rolled back" (#25532)
Browse files Browse the repository at this point in the history
Accessing the run_id(self.run_id) on exception leads to error because sessions are invalidated on exception. Here we extract the run_id before handling the exception

(cherry picked from commit 5668888)
  • Loading branch information
ephraimbuddy committed Aug 15, 2022
1 parent 385f04b commit 18f1338
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion airflow/models/dagrun.py
Expand Up @@ -1044,6 +1044,10 @@ def _create_task_instances(
:param session: the session to use
"""
# Fetch the information we need before handling the exception to avoid
# PendingRollbackError due to the session being invalidated on exception
# see https://github.com/apache/superset/pull/530
run_id = self.run_id
try:
if hook_is_noop:
session.bulk_insert_mappings(TI, tasks)
Expand All @@ -1057,7 +1061,7 @@ def _create_task_instances(
self.log.info(
'Hit IntegrityError while creating the TIs for %s- %s',
dag_id,
self.run_id,
run_id,
exc_info=True,
)
self.log.info('Doing session rollback.')
Expand Down

0 comments on commit 18f1338

Please sign in to comment.