[Twisted-Python] PATCH: runQuery

Federico Di Gregorio fog at initd.org
Thu Mar 6 09:04:44 EST 2003


while patching runQuery to solve my postgresql/psycopg problems i
discovered a much problematic problem.

essentially if a query run through runQuery raise an exception, the
exception is propagated but rollback() is never called on the
connection. this leaves the connection in a "dirty" state and the
effects on the next query are database dependent (postgresql, for
example,  will simply discard all following queries until next
rollback()).

a patch follows:

--- adbapi.py-old       2003-03-06 12:48:02.000000000 +0100
+++ adbapi.py   2003-03-06 13:02:33.000000000 +0100
@@ -94,9 +94,12 @@
     def _runQuery(self, args, kw):
         conn = self.connect()
         curs = conn.cursor()
-        apply(curs.execute, args, kw)
-        result = curs.fetchall()
-        curs.close()
+       try:
+           apply(curs.execute, args, kw)
+           result = curs.fetchall()
+           curs.close()
+       finally:
+           conn.rollback()
         return result
  
     def _runOperation(self, args, kw):

-- 
Federico Di Gregorio
Debian GNU/Linux Developer                                fog at debian.org
INIT.D Developer                                           fog at initd.org
                             Best friends are often failed lovers. -- Me
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20030306/de97b76a/attachment.pgp 


More information about the Twisted-Python mailing list