From: | Daniel Fortunov <postgresql(at)danielfortunov(dot)com> |
---|---|
To: | Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com> |
Cc: | Paolo De Stefani <paolo(at)paolodestefani(dot)it>, Psycopg <psycopg(at)postgresql(dot)org> |
Subject: | Re: psycopg3 transactions |
Date: | 2021-10-13 23:28:11 |
Message-ID: | CAH1rg6ZoQm=STwMR6AQ_FggxRxUn7qH_tLkRTfJTVYYdbTeL6w@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | psycopg |
On Wed, 13 Oct 2021 at 20:06, Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Reuben Rissler | 2021-10-14 00:14:53 | Re: psycopg3 transactions |
Previous Message | Paolo De Stefani | 2021-10-13 18:40:07 | Re: psycopg3 transactions |