public inbox for [email protected]  
help / color / mirror / Atom feed
From: Daniel Fortunov <[email protected]>
To: Karsten Hilbert <[email protected]>
Cc: Daniele Varrazzo <[email protected]>
Cc: Paolo De Stefani <[email protected]>
Cc: Psycopg <[email protected]>
Subject: Re: Re: psycopg3 transactions
Date: Thu, 14 Oct 2021 12:08:11 +0100
Message-ID: <CAH1rg6av5MR+yhEpwaxZNH+QrW+9ya9BQTx+w_Q9crm3e65yZQ@mail.gmail.com> (raw)
In-Reply-To: <trinity-cf9ddf31-623c-4512-beff-cf6d6d0116b8-1634205902640@3c-app-gmx-bs43>
References: <[email protected]>
	<CA+mi_8bXjHTrzDLQ+n_6K2MHVsr0J32X1HA28Ey9O+-Zm6JaeQ@mail.gmail.com>
	<[email protected]>
	<CA+mi_8afF2jMifiLSvL99+Ztupy1me7xDNAv0g47WxHWbwN9vw@mail.gmail.com>
	<CAH1rg6ZoQm=STwMR6AQ_FggxRxUn7qH_tLkRTfJTVYYdbTeL6w@mail.gmail.com>
	<trinity-cf9ddf31-623c-4512-beff-cf6d6d0116b8-1634205902640@3c-app-gmx-bs43>

On Thu, 14 Oct 2021, 11:05 Karsten Hilbert, <[email protected]> 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.)


view thread (28+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected]
  Subject: Re: Re: psycopg3 transactions
  In-Reply-To: <CAH1rg6av5MR+yhEpwaxZNH+QrW+9ya9BQTx+w_Q9crm3e65yZQ@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox