summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/engine/base.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-01-12 19:43:13 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2014-01-12 19:43:13 -0500
commit9c64607572a04eb2ed7981db8999732100f39d4d (patch)
tree111f47a4d93fcd1c86800d16b9797b2f991d7caa /lib/sqlalchemy/engine/base.py
parentc91fd822bc9816827d0aab4699e304ab49ed8280 (diff)
downloadsqlalchemy-9c64607572a04eb2ed7981db8999732100f39d4d.tar.gz
- :class:`.Connection` now associates a new
:class:`.RootTransaction` or :class:`.TwoPhaseTransaction` with its immediate :class:`._ConnectionFairy` as a "reset handler" for the span of that transaction, which takes over the task of calling commit() or rollback() for the "reset on return" behavior of :class:`.Pool` if the transaction was not otherwise completed. This resolves the issue that a picky transaction like that of MySQL two-phase will be properly closed out when the connection is closed without an explicit rollback or commit (e.g. no longer raises "XAER_RMFAIL" in this case - note this only shows up in logging as the exception is not propagated within pool reset). This issue would arise e.g. when using an orm :class:`.Session` with ``twophase`` set, and then :meth:`.Session.close` is called without an explicit rollback or commit. The change also has the effect that you will now see an explicit "ROLLBACK" in the logs when using a :class:`.Session` object in non-autocommit mode regardless of how that session was discarded. Thanks to Jeff Dairiki and Laurence Rowe for isolating the issue here. [ticket:2907]
Diffstat (limited to 'lib/sqlalchemy/engine/base.py')
-rw-r--r--lib/sqlalchemy/engine/base.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py
index ff2e6e282..5c66f4806 100644
--- a/lib/sqlalchemy/engine/base.py
+++ b/lib/sqlalchemy/engine/base.py
@@ -404,7 +404,7 @@ class Connection(Connectable):
"""
if self.__transaction is None:
- self.__transaction = RootTransaction(self)
+ self.__transaction = self.connection._reset_agent = RootTransaction(self)
return self.__transaction
else:
return Transaction(self, self.__transaction)
@@ -425,7 +425,7 @@ class Connection(Connectable):
"""
if self.__transaction is None:
- self.__transaction = RootTransaction(self)
+ self.__transaction = self.connection._reset_agent = RootTransaction(self)
else:
self.__transaction = NestedTransaction(self, self.__transaction)
return self.__transaction
@@ -453,7 +453,7 @@ class Connection(Connectable):
"is already in progress.")
if xid is None:
xid = self.engine.dialect.create_xid()
- self.__transaction = TwoPhaseTransaction(self, xid)
+ self.__transaction = self.connection._reset_agent = TwoPhaseTransaction(self, xid)
return self.__transaction
def recover_twophase(self):
@@ -491,11 +491,11 @@ class Connection(Connectable):
self.engine.logger.info("ROLLBACK")
try:
self.engine.dialect.do_rollback(self.connection)
- self.__transaction = None
+ self.__transaction = self.connection._reset_agent = None
except Exception as e:
self._handle_dbapi_exception(e, None, None, None, None)
else:
- self.__transaction = None
+ self.__transaction = self.connection._reset_agent = None
def _commit_impl(self, autocommit=False):
if self._has_events:
@@ -505,7 +505,7 @@ class Connection(Connectable):
self.engine.logger.info("COMMIT")
try:
self.engine.dialect.do_commit(self.connection)
- self.__transaction = None
+ self.__transaction = self.connection._reset_agent = None
except Exception as e:
self._handle_dbapi_exception(e, None, None, None, None)
@@ -560,7 +560,7 @@ class Connection(Connectable):
if self._still_open_and_connection_is_valid:
assert isinstance(self.__transaction, TwoPhaseTransaction)
self.engine.dialect.do_rollback_twophase(self, xid, is_prepared)
- self.__transaction = None
+ self.__transaction = self.connection._reset_agent = None
def _commit_twophase_impl(self, xid, is_prepared):
if self._has_events:
@@ -569,7 +569,7 @@ class Connection(Connectable):
if self._still_open_and_connection_is_valid:
assert isinstance(self.__transaction, TwoPhaseTransaction)
self.engine.dialect.do_commit_twophase(self, xid, is_prepared)
- self.__transaction = None
+ self.__transaction = self.connection._reset_agent = None
def _autorollback(self):
if not self.in_transaction():