[Twisted-Python] PATCH: runQuery
Dave Peticolas
dave at krondo.com
Thu Mar 6 15:53:03 EST 2003
On Thu, 2003-03-06 at 06:04, Federico Di Gregorio wrote:
> 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):
Good catch! I wonder, though, shouldn't we be calling
commit() instead of rollback()? What if the query had
side-effects in the database, won't it undo those
changes?
dave
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20030306/9e792846/attachment.pgp
More information about the Twisted-Python
mailing list