Re: psycopg3 transactions

From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>, Paolo De Stefani <paolo(at)paolodestefani(dot)it>, Psycopg <psycopg(at)postgresql(dot)org>
Subject: Re: psycopg3 transactions
Date: 2021-10-20 20:07:13
Message-ID: CABUevExE-Ts9C4XECW4USwxMGtte93dezA+0S9akYszHd75guA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On Sun, Oct 17, 2021 at 12:59 AM Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net>
wrote:

> Am Sun, Oct 17, 2021 at 12:48:40AM +0200 schrieb Karsten Hilbert:
>
> > > https://www.psycopg.org/psycopg3/docs/basic/transactions.html
> >
> > I am sorry to say this but this concept:
> >
> > This way we don’t have to remember to call neither
> > close() nor commit() and the database operation have
> > actually a persistent effect.
> >
> > seems fundamentally flawed to me in terms of databases.
> > Actually changing the content of a database should be a
> > conscious decision by program(mer) logic.
>
> I could, perhaps, agree with the *transaction* context
> manager being default-commit because:
>
> - after the context block the transaction has gone away
>
> - hence what happens inside either failed (auto-rollback)
>
> - or is to be committed
>
> Not so for the *connection* context manager.
>

Just to chime in here as well, but this is pretty much what I was trying to
say in the thread on Twitter (before I realized I was on this list and
should've replied here). I have no problem with the transaction context
manager working like that, but for the "connectoin" one it's very strange
and it's dangerous in that it behaves differently when it's used as a
context manager and when it's not.

--
Magnus Hagander
Me: https://www.hagander.net/ <http://www.hagander.net/>
Work: https://www.redpill-linpro.com/ <http://www.redpill-linpro.com/>

In response to

Browse psycopg by date

  From Date Subject
Next Message Daniele Varrazzo 2021-10-21 10:52:40 Re: psycopg3 transactions
Previous Message Karsten Hilbert 2021-10-16 22:58:48 Re: psycopg3 transactions