summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorplumSemPy <emin@berkekely.edu>2017-01-04 12:06:48 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2017-01-04 12:12:52 -0500
commitcd95d4a5b928a6bc4f07c988ba3791a0a63c8d15 (patch)
tree327e48818ed5aef6d3d7c67ee441bfbd10dcd089 /lib/sqlalchemy
parenta030bc9f171f6692e08eb7604f29e4bc6d51a574 (diff)
downloadsqlalchemy-cd95d4a5b928a6bc4f07c988ba3791a0a63c8d15.tar.gz
Ensure session.no_autoflush uses finally
The :attr:`.Session.no_autoflush` context manager now ensures that the autoflush flag is reset within a "finally" block, so that if an exception is raised within the block, the state still resets appropriately. Pull request courtesy Emin Arakelian. Change-Id: Ib19ddf32074b1df82a6a1f1ae14e3a962cd31a5f Pull-request: https://github.com/zzzeek/sqlalchemy/pull/335
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/orm/session.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py
index b39ba1465..cb1ebf013 100644
--- a/lib/sqlalchemy/orm/session.py
+++ b/lib/sqlalchemy/orm/session.py
@@ -1354,8 +1354,10 @@ class Session(_SessionClassMethods):
"""
autoflush = self.autoflush
self.autoflush = False
- yield self
- self.autoflush = autoflush
+ try:
+ yield self
+ finally:
+ self.autoflush = autoflush
def _autoflush(self):
if self.autoflush and not self._flushing: