summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/engine/base.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-12-01 19:27:25 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2021-12-06 13:05:44 -0500
commita845da8b0fc5bb172e278c399a1de9a2e49d62af (patch)
treeca86fe60e4e69fdef15cb9593d57d9042678700f /lib/sqlalchemy/engine/base.py
parent55e0497b080bf7f5159faa5abcb341269ebfdc7f (diff)
downloadsqlalchemy-a845da8b0fc5bb172e278c399a1de9a2e49d62af.tar.gz
contextmanager skips rollback if trans says to skip it
Fixed issue where if an exception occurred when the :class:`_orm.Session` were to close the connection within the :meth:`_orm.Session.commit` method, when using a context manager for :meth:`_orm.Session.begin` , it would attempt a rollback which would not be possible as the :class:`_orm.Session` was in between where the transaction is committed and the connection is then to be returned to the pool, raising the exception "this sessiontransaction is in the committed state". This exception can occur mostly in an asyncio context where CancelledError can be raised. Fixes: #7388 Change-Id: I1a85a3a7eae79f3553ddf1e3d245a0d90b0a2f40
Diffstat (limited to 'lib/sqlalchemy/engine/base.py')
-rw-r--r--lib/sqlalchemy/engine/base.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py
index fbd8fe7df..b11ffd871 100644
--- a/lib/sqlalchemy/engine/base.py
+++ b/lib/sqlalchemy/engine/base.py
@@ -2022,6 +2022,13 @@ class Transaction(TransactionalContext):
def _transaction_is_closed(self):
return not self._deactivated_from_connection
+ def _rollback_can_be_called(self):
+ # for RootTransaction / NestedTransaction, it's safe to call
+ # rollback() even if the transaction is deactive and no warnings
+ # will be emitted. tested in
+ # test_transaction.py -> test_no_rollback_in_deactive(?:_savepoint)?
+ return True
+
class RootTransaction(Transaction):
"""Represent the "root" transaction on a :class:`_engine.Connection`.