Skip to content

Commit

Permalink
Merge pull request #17598 from mvdbeek/fix_pending_rollback_error
Browse files Browse the repository at this point in the history
[23.2] Anticipate PendingRollbackError in ``check_database_connection``
  • Loading branch information
mvdbeek authored Mar 6, 2024
2 parents 98c80e7 + 149e281 commit 6728e48
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/galaxy/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,13 @@ def check_database_connection(session):
by rolling back the invalidated transaction.
Ref: https://docs.sqlalchemy.org/en/14/errors.html#can-t-reconnect-until-invalid-transaction-is-rolled-back
"""
if session and session.connection().invalidated:
log.error("Database transaction rolled back due to invalid state.")
assert session
if isinstance(session, scoped_session):
session = session()
trans = session.get_transaction()
if (trans and not trans.is_active) or session.connection().invalidated:
session.rollback()
log.error("Database transaction rolled back due to inactive session transaction or invalid connection state.")


# TODO: Refactor this to be a proper class, not a bunch.
Expand Down

0 comments on commit 6728e48

Please sign in to comment.