Re: psycopg3 transactions - Mailing list psycopg

From Reuben Rissler
Subject Re: psycopg3 transactions
Date
Msg-id c394395a-75c4-a076-65ac-20bdf3010953@emypeople.net
Whole thread Raw
In response to Re: psycopg3 transactions  (Daniel Fortunov <postgresql@danielfortunov.com>)
List psycopg


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


I was going to disagree with this, as some things don't work in an ACID way in autocommit. Then I read point 2, now I'm going to try this and see how I like transactions vs commit/rollback.

Reuben Rissler

psycopg by date:

Previous
From: Daniel Fortunov
Date:
Subject: Re: psycopg3 transactions
Next
From: Karsten Hilbert
Date:
Subject: Aw: Re: psycopg3 transactions