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
  • Loading branch information
ephraimbuddy committed Aug 5, 2022
1 parent 4193558 commit 5668888
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion airflow/models/dagrun.py
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 5668888

Please sign in to comment.