diff options
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/engine/base.py | 24 | ||||
-rw-r--r-- | lib/sqlalchemy/pool/base.py | 20 |
2 files changed, 39 insertions, 5 deletions
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index a2066de4a..ed0586cc7 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -689,6 +689,7 @@ class Connection(Connectable): self._autobegin() else: self._transaction = RootTransaction(self) + self.connection._reset_agent = self._transaction return self._transaction trans = NestedTransaction(self, self._transaction) @@ -819,10 +820,27 @@ class Connection(Connectable): if trans._is_root: assert trans._parent is trans self._transaction = None + + # test suite w/ SingletonThreadPool will have cases + # where _reset_agent is on a different Connection + # entirely so we can't assert this here. + # if ( + # not self._is_future + # and self._still_open_and_connection_is_valid + # ): + # assert self.__connection._reset_agent is None else: assert trans._parent is not trans self._transaction = trans._parent + # not doing this assertion for now, however this is how + # it would look: + # if self._still_open_and_connection_is_valid: + # trans = self._transaction + # while not trans._is_root: + # trans = trans._parent + # assert self.__connection._reset_agent is trans + def _rollback_to_savepoint_impl( self, name, context, deactivate_only=False ): @@ -1965,10 +1983,10 @@ class Transaction(object): an enclosing transaction. """ - if not self._parent.is_active: - return - if self._parent is self: + + if self._parent.is_active and self._parent is self: self.rollback() + self.connection._discard_transaction(self) def rollback(self): """Roll back this :class:`.Transaction`. diff --git a/lib/sqlalchemy/pool/base.py b/lib/sqlalchemy/pool/base.py index ef4a12248..f20b63cf5 100644 --- a/lib/sqlalchemy/pool/base.py +++ b/lib/sqlalchemy/pool/base.py @@ -807,7 +807,15 @@ class _ConnectionFairy(object): ", via agent" if self._reset_agent else "", ) if self._reset_agent: - self._reset_agent.rollback() + if not self._reset_agent.is_active: + util.warn( + "Reset agent is not active. " + "This should not occur unless there was already " + "a connectivity error in progress." + ) + pool._dialect.do_rollback(self) + else: + self._reset_agent.rollback() else: pool._dialect.do_rollback(self) elif pool._reset_on_return is reset_commit: @@ -818,7 +826,15 @@ class _ConnectionFairy(object): ", via agent" if self._reset_agent else "", ) if self._reset_agent: - self._reset_agent.commit() + if not self._reset_agent.is_active: + util.warn( + "Reset agent is not active. " + "This should not occur unless there was already " + "a connectivity error in progress." + ) + pool._dialect.do_commit(self) + else: + self._reset_agent.commit() else: pool._dialect.do_commit(self) |