]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
put a try/finally to insure that SQLSession is cleaned out on rollback/commit regardl...
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 17 Mar 2006 22:00:24 +0000 (22:00 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 17 Mar 2006 22:00:24 +0000 (22:00 +0000)
lib/sqlalchemy/engine.py

index 95566b2ba8f9f0df6f0a0a2a919b428bcb66e143..79902446d61a6927b67c38e7e7fee90c39a0b677 100644 (file)
@@ -199,15 +199,19 @@ class SQLSession(object):
     def rollback(self):
         """rolls back the transaction on this SQLSession's connection.  this can be called regardless of the "begin" counter value, i.e. can be called from anywhere inside a callstack.  the "begin" counter is cleared."""
         if self.__tcount > 0:
-            self.engine.do_rollback(self.connection)
-            del self.__transaction
-            self.__tcount = 0
+            try:
+                self.engine.do_rollback(self.connection)
+            finally:
+                del self.__transaction
+                self.__tcount = 0
     def commit(self):
         """commits the transaction started by begin().  If begin() was called multiple times, a counter will be decreased for each call to commit(), with the actual commit operation occuring when the counter reaches zero.  this is to provide "nested" behavior of transactions so that different functions in a particular call stack can call begin()/commit() independently of each other without knowledge of an existing transaction."""
         if self.__tcount == 1:
-            self.engine.do_commit(self.connection)
-            del self.__transaction
-            self.__tcount = 0
+            try:
+                self.engine.do_commit(self.connection)
+            finally:
+                del self.__transaction
+                self.__tcount = 0
         elif self.__tcount > 1:
             self.__tcount -= 1
     def is_begun(self):