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 1manfi-0003fL-RK for psycopg@arkaria.postgresql.org; Wed, 13 Oct 2021 23:28:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1manfg-0001Gp-Mb for psycopg@arkaria.postgresql.org; Wed, 13 Oct 2021 23:28:28 +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 1manfg-0001G2-C3 for psycopg@lists.postgresql.org; Wed, 13 Oct 2021 23:28:28 +0000 Received: from mail-ed1-f51.google.com ([209.85.208.51]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1manfd-0005HM-U7 for psycopg@postgresql.org; Wed, 13 Oct 2021 23:28:27 +0000 Received: by mail-ed1-f51.google.com with SMTP id y12so17184000eda.4 for ; Wed, 13 Oct 2021 16:28:25 -0700 (PDT) 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:cc; bh=A7ZTImpxVQ9laOUjJPuuftmGuzX2JEnIDXzFjGSky2E=; b=Fsl/QNrP0iVN51GHqYUAWazX/3i/b5nbdL9MF7i5PUYchOGl7Ck5VOX0p6ssGTIM5p 1f9wfWRMFV/d0fNzh1vg4Bp//Kbb4sJ3LvSLBuQYHzULzvrc/EGguqyAJQgPAWPF98Hp +sHa5CvghJ2IoqKJjsOaqOWzW9/mjPsVacn7SiWwxhnIGZt1AnVtZZ4v3Zq1UFVc3axz lodat38vf3k+mkxl0BcJpiH7C3AHmCwot1Z/5lMgGTzTBwnnmxJ8HCIVn57r0TNq4/8F 5Ft6TP5W9HqnfVeHMSZBWNLDuiBICnt2IUvzVMGnaNNVXlqAQR+dtWPs4J0eWFbaXomQ QPhA== X-Gm-Message-State: AOAM531B9mRYj1YoxHYrq6cilS3ss+XYBpHoSQgfXX4siDKnAF9h/gt8 HDGhM93f3lsS0SN5qI2NvSHncz5M4u6REcS6pgU= X-Google-Smtp-Source: ABdhPJz9C29Decm0g9um7dv1YUi8pAqfQBgqfgNWL3jhPAmA3phSwdo/LHFyiCaOfsyHS5mlDxPxiLTBowVHecNI0TE= X-Received: by 2002:a17:906:a0c9:: with SMTP id bh9mr2526173ejb.51.1634167704549; Wed, 13 Oct 2021 16:28:24 -0700 (PDT) MIME-Version: 1.0 References: <9a99d2d110b121542d1ea0a05066858b@paolodestefani.it> In-Reply-To: From: Daniel Fortunov Date: Thu, 14 Oct 2021 00:28:11 +0100 Message-ID: Subject: Re: psycopg3 transactions To: Daniele Varrazzo Cc: Paolo De Stefani , Psycopg Content-Type: multipart/alternative; boundary="000000000000887e4a05ce445116" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000887e4a05ce445116 Content-Type: text/plain; charset="UTF-8" On Wed, 13 Oct 2021 at 20:06, Daniele Varrazzo wrote: > > I think we can improve the documentation there by extending more about > the effects of the interaction between DBAPI transactions and the > transaction() blocks. And things are definitely more intuitive if > transaction() is used in autocommit: we might want to advise people to > do that. > 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 --000000000000887e4a05ce445116 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Wed, 13 Oct 2021 at 20:06, Daniele Var= razzo <daniele.varrazzo@gm= ail.com> wrote:

I think we can improve the documentation there by extending more about
the effects of the interaction between DBAPI transactions and the
transaction() blocks. And things are definitely more intuitive if
transaction() is used in autocommit: we might want to advise people to
do that.

Agree. The DBAPI choice to man= date that autocommit be off by default is a strange and unfortunate choice = that in my experience leads to a never ending series of "surprises&quo= t; such as this one.

My conclusion is that the onl= y sane thing to do is:
1. Only ever create connections in autocom= mit mode.
2. Only ever use `with connection.transaction()` to con= trol transactions.
3. Forget that `connection.commit()` and `conn= ection.rollback()` exist, and never use them.

I= 9;m in favour of recommending this as strongly=C2=A0as reasonably possible = in the documentation.

It's a shame that 1 is n= ot the default. So you still have to remember to not forget to do this expl= icitly, every time you create a connection.

Dani
--000000000000887e4a05ce445116--