Skip to content

Commit

Permalink
Explicitly check for transaction state
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavcs committed Mar 5, 2024
1 parent ffa58ae commit 6a35256
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lib/galaxy/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
)

from sqlalchemy import event
from sqlalchemy.exc import PendingRollbackError
from sqlalchemy.orm import (
scoped_session,
Session,
Expand Down Expand Up @@ -67,13 +66,10 @@ 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
"""
try:
if session and session.connection().invalidated:
log.error("Database transaction rolled back due to invalid state.")
session.rollback()
except PendingRollbackError:
log.error("Database transaction rolled back.")
assert session
if not session.get_transaction().is_active or session.connection().invalidated:
session.rollback()
log.error("Database transaction rolled back due to inactive session transaction or invalid connectino state.")


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

0 comments on commit 6a35256

Please sign in to comment.