Merge "[sqlalchemy-20] Use session.transaction information to decide if active"

This commit is contained in:
Zuul 2022-06-09 15:29:12 +00:00 committed by Gerrit Code Review
commit 3733520df6
1 changed files with 3 additions and 3 deletions

View File

@ -1037,14 +1037,14 @@ def is_session_active(session):
session transaction will not end at the end of a reader/writer context.
In this case, a session could have an active transaction even when it is
not inside a reader/writer context. In order to mimic the previous
behaviour, this method checks the pending new, deleted and dirty elements
to be flushed.
behaviour, this method checks if there is a transaction created and if
the transaction has any active connection against the database server.
"""
if session.autocommit: # old behaviour, to be removed with sqlalchemy 2.0
return session.is_active
if not session.transaction:
return False
if not (session.dirty or session.deleted or session.new):
if not session.transaction._connections:
return False
return True