From 1d4041e6ac5e04150eb030bc0a2460579d4b7a7f Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 17 Mar 2006 22:00:24 +0000 Subject: [PATCH] put a try/finally to insure that SQLSession is cleaned out on rollback/commit regardless of issues --- lib/sqlalchemy/engine.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/sqlalchemy/engine.py b/lib/sqlalchemy/engine.py index 95566b2ba8..79902446d6 100644 --- a/lib/sqlalchemy/engine.py +++ b/lib/sqlalchemy/engine.py @@ -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): -- 2.47.2