summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/engine
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-06-12 13:09:15 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-06-12 20:28:37 -0400
commit5624430eb1d07c68d0931bc89f7146bc003fde19 (patch)
tree2bfa7f881dec583d0c72f617222e17e9d900ff20 /lib/sqlalchemy/engine
parentdbaf82d258cc12d92ef28de4677d147fdb7808fd (diff)
downloadsqlalchemy-5624430eb1d07c68d0931bc89f7146bc003fde19.tar.gz
Warn when transaction context manager ends on inactive transaction
if .rollback() or .commit() is called inside the transaction context manager, the transaction object is deactivated. the context manager continues but will not be able to correctly fulfill it's closing state. Ensure a warning is emitted when this happens. Change-Id: I8fc3a73f7c21575dda5bcbd6fb74ddb679771630
Diffstat (limited to 'lib/sqlalchemy/engine')
-rw-r--r--lib/sqlalchemy/engine/base.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py
index 3e02a29fe..81c0c9f58 100644
--- a/lib/sqlalchemy/engine/base.py
+++ b/lib/sqlalchemy/engine/base.py
@@ -2095,6 +2095,9 @@ class RootTransaction(Transaction):
):
self.connection._dbapi_connection._reset_agent = None
+ elif self.connection._transaction is not self:
+ util.warn("transaction already deassociated from connection")
+
# we have tests that want to make sure the pool handles this
# correctly. TODO: how to disable internal assertions cleanly?
# else:
@@ -2133,7 +2136,7 @@ class RootTransaction(Transaction):
def _connection_commit_impl(self):
self.connection._commit_impl()
- def _close_impl(self):
+ def _close_impl(self, try_deactivate=False):
try:
if self.is_active:
self._connection_rollback_impl()
@@ -2141,7 +2144,7 @@ class RootTransaction(Transaction):
if self.connection._nested_transaction:
self.connection._nested_transaction._cancel()
finally:
- if self.is_active:
+ if self.is_active or try_deactivate:
self._deactivate_from_connection()
if self.connection._transaction is self:
self.connection._transaction = None
@@ -2153,7 +2156,7 @@ class RootTransaction(Transaction):
self._close_impl()
def _do_rollback(self):
- self._close_impl()
+ self._close_impl(try_deactivate=True)
def _do_commit(self):
if self.is_active: