summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-03-11 10:52:43 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2017-03-14 15:40:31 -0400
commit4ece86eb41274ba059211807e23273178c3c3384 (patch)
tree46bee27a53626f467530eb4e78cc7abc4beae843 /lib/sqlalchemy
parent596e322543df6ff380243c9cb0cf9997252329f6 (diff)
downloadsqlalchemy-4ece86eb41274ba059211807e23273178c3c3384.tar.gz
Emit after_rollback() event before snapshot removal
The state of the :class:`.Session` is now present when the :meth:`.SessionEvents.after_rollback` event is emitted, that is, the attribute state of objects prior to their being expired. This is now consistent with the behavior of the :meth:`.SessionEvents.after_commit` event which also emits before the attribute state of objects is expired. Change-Id: I9c572656ec5a9bfaeab817e9c95107c75aca1b51 Fixes: #3934
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/orm/session.py26
1 files changed, 12 insertions, 14 deletions
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py
index 081920487..2d3cb1b08 100644
--- a/lib/sqlalchemy/orm/session.py
+++ b/lib/sqlalchemy/orm/session.py
@@ -277,9 +277,9 @@ class SessionTransaction(object):
)
elif not deactive_ok:
raise sa_exc.InvalidRequestError(
- "This Session's transaction has been rolled back "
- "by a nested rollback() call. To begin a new "
- "transaction, issue Session.rollback() first."
+ "This session is in 'inactive' state, due to the "
+ "SQL transaction being rolled back; no further "
+ "SQL can be emitted within this transaction."
)
elif self._state is CLOSED:
raise sa_exc.ResourceClosedError(closed_msg)
@@ -487,10 +487,17 @@ class SessionTransaction(object):
for transaction in self._iterate_self_and_parents():
if transaction._parent is None or transaction.nested:
try:
- transaction._rollback_impl()
+ for t in set(transaction._connections.values()):
+ t[1].rollback()
+
+ transaction._state = DEACTIVE
+ self.session.dispatch.after_rollback(self.session)
except:
rollback_err = sys.exc_info()
- transaction._state = DEACTIVE
+ finally:
+ if self.session._enable_transaction_accounting:
+ transaction._restore_snapshot(
+ dirty_only=transaction.nested)
boundary = transaction
break
else:
@@ -521,15 +528,6 @@ class SessionTransaction(object):
return self._parent
- def _rollback_impl(self):
- try:
- for t in set(self._connections.values()):
- t[1].rollback()
- finally:
- if self.session._enable_transaction_accounting:
- self._restore_snapshot(dirty_only=self.nested)
-
- self.session.dispatch.after_rollback(self.session)
def close(self, invalidate=False):
self.session.transaction = self._parent