Skip to content

Commit

Permalink
Fix "This Session's transaction has been rolled back"
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
  • Loading branch information
ephraimbuddy committed Aug 5, 2022
1 parent 55d0b9f commit 0409c12
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion airflow/models/dagrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,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 @@ -1151,7 +1155,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 0409c12

Please sign in to comment.