Re: Transaction control overhauling - Mailing list psycopg
From | Federico Di Gregorio |
---|---|
Subject | Re: Transaction control overhauling |
Date | |
Msg-id | 4DCB93CE.4030805@dndg.it Whole thread Raw |
In response to | Transaction control overhauling (Daniele Varrazzo <daniele.varrazzo@gmail.com>) |
Responses |
Re: Transaction control overhauling
|
List | psycopg |
On 12/05/11 00:43, Daniele Varrazzo wrote: > Hello, > > I think psycopg needs some cleanup in the area of the transactions control. [snip] Hi Daniele, I pretty much agree with your analisys, I just have a couple of comments: > I. don't issue any query at startup and, by default, don't pass any > isolation level together with BEGIN: > > II. add a method conn.set_transaction(isolation_level=None, > read_only=None, deferrable=None) allowing to change one or more of the > transaction settings. Calling the method would terminate the current > transaction and put the new settings in place. Note that there are > several ways for implementing this: I'd make this a keyword argument function with the following signature: conn.set_transaction( isolation_level=None, autocommit=None, deferrable=None, readonly=None) to keep everything related to transaction management in a single function. I don't like the proposed autocommit() method because it is yet another DBAPI extension and must keep that to a minimum. Also, I sorted the parameters in set_transaction() from the probably most used to least. > II. 1. store variables in the connection object and pass the relative > SET TRANSACTION at the following BEGIN > > II. 2. run a query SET SESSION CHARACTERISTICS AS ... and not store > anything in the connection status > > II. 3. run a query to set the GUC instead (SET default_whatever AS > value): very similar to II. 2., but it also allows passing the value > "default", meaning "reset to the configuration value", an option > apparently missing with the SET SESSION CHARACTERISTICS syntax. Do we need the ability to pass "default"? When the user call set_transaction() with missing or None parameters do we want to send "default" or stay with the current value? I favor the latter, e.g., conn.set_transaction(isolation_level=XXX, deferrable=YYY) should not reset the autocommit or readonly values to default. > III. add an independent method conn.autocommit(value=True). A less > verbose method for a frequently used functionality. Nope, see above. > IV. for backwards compatibility, convert isolation_level into a > property, querying the server to know the current status. Yesss. > > V. keep set_isolation_level() for backwards compatibility, converting > it into a wrapper for the other methods. Yesss. federico -- Federico Di Gregorio federico.digregorio@dndg.it Studio Associato Di Nunzio e Di Gregorio http://dndg.it In some countries (e.g., Germany) even many brands of toilet paper have format A6. [http://www.cl.cam.ac.uk/~mgk25/iso-paper.html]