From 5b1dab0e8f6d27dabfa5088f950a2d4ad186e0a5 Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Fri, 22 Jul 2022 03:44:21 +0200 Subject: [PATCH] [sqlalchemy-20] Use session.transaction information to decide if active The "session.transaction" member "_connections" is a dictionary with the active database connections of the current transaction. Neutron will use it to determine if the session is active or not. This parameter will provide more accurate information than "new", "dirty" or "deleted". A read (SELECT) operation won't be included on those lists while the transaction is currently active. This patch is patch is a direct transcription of [1]. [1]https://review.opendev.org/c/openstack/neutron/+/843256 Related-Bug: #1975542 Change-Id: Ibc04a1940c3833d3e10dbfc011598ac11c58ba13 --- neutron_lib/db/api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/neutron_lib/db/api.py b/neutron_lib/db/api.py index 5149d160b..8a938c20b 100644 --- a/neutron_lib/db/api.py +++ b/neutron_lib/db/api.py @@ -473,14 +473,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 getattr(session, 'autocommit', None): # 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