Re: Re: psycopg3 transactions
От | Daniel Fortunov |
---|---|
Тема | Re: Re: psycopg3 transactions |
Дата | |
Msg-id | CAH1rg6av5MR+yhEpwaxZNH+QrW+9ya9BQTx+w_Q9crm3e65yZQ@mail.gmail.com обсуждение исходный текст |
Ответ на | Aw: Re: psycopg3 transactions (Karsten Hilbert <Karsten.Hilbert@gmx.net>) |
Ответы |
Re: Re: psycopg3 transactions
|
Список | psycopg |
On Thu, 14 Oct 2021, 11:05 Karsten Hilbert, <Karsten.Hilbert@gmx.net> wrote:
>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.
What if you need to rollback a hitherto valid transaction ?
Transactions are there for a reason. It seems best to explicitely use them ?
I'm not sure I fully understand your question/statement but let me try to respond.
We are still "using transactions", just with more precise, more explicit*, and more flexible* semantics, represented by a context manager.
Rolling back a transaction is possible by raising a Rollback exception within a block.
I hope this answers your question but if not please describe the scenario you are thinking about.
Dani
(*More explicit because in the conventional autocommit=false approach, the beginning of the transaction is an implicit side-effect of executing another statement, which may or may not actually begin a transaction depending on whether one is in progress. More flexible because you can have nested transaction blocks which operate in an independent and composable way.)
В списке psycopg по дате отправления: