Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mdHs4-0004kn-CW for psycopg@arkaria.postgresql.org; Wed, 20 Oct 2021 20:07:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mdHs2-0006tC-3c for psycopg@arkaria.postgresql.org; Wed, 20 Oct 2021 20:07:30 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mdHs1-0006t3-Tk for psycopg@lists.postgresql.org; Wed, 20 Oct 2021 20:07:29 +0000 Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mdHry-0006rL-Vx for psycopg@postgresql.org; Wed, 20 Oct 2021 20:07:28 +0000 Received: by mail-lf1-x132.google.com with SMTP id t9so287310lfd.1 for ; Wed, 20 Oct 2021 13:07:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hagander-net.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=1S1vq61zIsC7H/vpnlEfnB5X9w55LkfOs2o2Xxz3WHE=; b=4ZLI5N2CRutMxmF1UL1aDOeedE5v4MovTGRzZM5X9eiZU3K0pzSvczRXr1HX0kisyX QERUz57rnlzc0Hd6plFrUWhNlT4tDEp51MqrMeXOcZSqz+A4h3nBZOWzBl3yIxcKFsxu sd800I2WDAVqENAg9NQae7xi0LNaSZ9mJHwZNs0Xhsn/oBJBMbLQEv2DvwVpRAUrtdWh Eik0rF/Mk1Lu7k5FJKQfkJUKHRw70d/aC15kS/Wb4lrRV9fV/rWiE4+12SGVYLisCzyE /2O8X9n0mUVOc8zQHfq+XOudDu+T9fr0BdOxcV4IpxNEUaAJgvb3SV/V5o5nhgj8NvJ/ Tbbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=1S1vq61zIsC7H/vpnlEfnB5X9w55LkfOs2o2Xxz3WHE=; b=upC7oglZZ7zulf1owucolJzjcyuLcoCcRf9bgO0Q6waMbc8LrFiwPYV2YTGUcxh66q o9e81XFuZDrtfCtiUuwskcvIhWpB5i+RZpCSqRg/VfmocslvKHCAbpYUVQbkh8TMfM6D yhivK5cHv7oroYyBJZfTSfNDpBWtNnpNlbGL0JLLivikHqDoFXM+k6I6l81TZCB7rJnz Pbo0NqSDST/QLUixmaPlTSd6lmgv5mua04SNKt1eI0sZGbDcwno+qsk4BMdiT9Y7iWy2 bymUQOYjSbQm7BqYkzuO8iF7mK1jMZe/GVd53cLMmc2DOYwQ4meeFskd0vr0zPWbduYa 59Dg== X-Gm-Message-State: AOAM531Fnt9CR3jji6796s7bcpA4swMdoqdItNqIpc9ZI+Zeb2ZUe4k7 dsFRQZa9xMrj0lZCeb2pNaBZw2OoA9v/arkOS3P4Xn8651s= X-Google-Smtp-Source: ABdhPJx+8u6rVBBMFS9t6HLt6TwPSei02am8HQe2B5PG86IMGUo4aUsqsuPZWV5cCR1vUvnewkG3kyS04yWD8AFIY3A= X-Received: by 2002:ac2:4bc1:: with SMTP id o1mr1197749lfq.633.1634760445051; Wed, 20 Oct 2021 13:07:25 -0700 (PDT) MIME-Version: 1.0 References: <9a99d2d110b121542d1ea0a05066858b@paolodestefani.it> <6683df3e65fe961aa478e61db7ad687d@paolodestefani.it> In-Reply-To: From: Magnus Hagander Date: Wed, 20 Oct 2021 22:07:13 +0200 Message-ID: Subject: Re: psycopg3 transactions To: Daniele Varrazzo , Paolo De Stefani , Psycopg Content-Type: multipart/alternative; boundary="0000000000009edaef05cece531d" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000009edaef05cece531d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Oct 17, 2021 at 12:59 AM Karsten Hilbert 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=E2=80=99t 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. --=20 Magnus Hagander Me: https://www.hagander.net/ Work: https://www.redpill-linpro.com/ --0000000000009edaef05cece531d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Sun, Oct 17, 2021 at 12:59 AM Karsten = Hilbert <Karsten.Hilbert@gmx.= net> wrote:
Am Sun, Oct 17, 2021 at 12:48:40AM +0200 schr= ieb Karsten Hilbert:

> > https://www.psycopg.org/psyco= pg3/docs/basic/transactions.html
>
> I am sorry to say this but this concept:
>
>=C2=A0 =C2=A0 =C2=A0 =C2=A0This way we don=E2=80=99t have to remember t= o call neither
>=C2=A0 =C2=A0 =C2=A0 =C2=A0close() nor commit() and the database operat= ion have
>=C2=A0 =C2=A0 =C2=A0 =C2=A0actually 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:

=C2=A0 =C2=A0 =C2=A0 =C2=A0 - after the context block the transaction has g= one away

=C2=A0 =C2=A0 =C2=A0 =C2=A0 - hence what happens inside either failed (auto= -rollback)

=C2=A0 =C2=A0 =C2=A0 =C2=A0 - 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 try= ing to say in the thread on Twitter (before I realized I was on this list a= nd should've replied here). I have no problem with the transaction cont= ext manager working like that, but for the "connectoin"=C2=A0one = 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.
=

--
=C2=A0Magnus Hagander
=C2=A0Me: https://www.hagander.net/
=C2=A0Work: <= a href=3D"http://www.redpill-linpro.com/" target=3D"_blank">https://www.red= pill-linpro.com/
--0000000000009edaef05cece531d--