Re: psycopg3 transactions - Mailing list psycopg

From Daniel Fortunov
Subject Re: psycopg3 transactions
Date
Msg-id CAH1rg6ZoQm=STwMR6AQ_FggxRxUn7qH_tLkRTfJTVYYdbTeL6w@mail.gmail.com
Whole thread Raw
In response to Re: psycopg3 transactions  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
Responses Re: psycopg3 transactions  (Reuben Rissler <silrep@emypeople.net>)
Aw: Re: psycopg3 transactions  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
List psycopg
On Wed, 13 Oct 2021 at 20:06, Daniele Varrazzo <daniele.varrazzo@gmail.com> wrote:

I think we can improve the documentation there by extending more about
the effects of the interaction between DBAPI transactions and the
transaction() blocks. And things are definitely more intuitive if
transaction() is used in autocommit: we might want to advise people to
do that.

Agree. The DBAPI choice to mandate that autocommit be off by default is a strange and unfortunate choice that in my experience leads to a never ending series of "surprises" such as this one.

My conclusion is that the only sane thing to do is:
1. Only ever create connections in autocommit mode.
2. Only ever use `with connection.transaction()` to control transactions.
3. Forget that `connection.commit()` and `connection.rollback()` exist, and never use them.

I'm in favour of recommending this as strongly as reasonably possible in the documentation.

It's a shame that 1 is not the default. So you still have to remember to not forget to do this explicitly, every time you create a connection.

Dani

psycopg by date:

Previous
From: Paolo De Stefani
Date:
Subject: Re: psycopg3 transactions
Next
From: Reuben Rissler
Date:
Subject: Re: psycopg3 transactions