summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-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: