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 1mdWkG-0006Et-G3 for psycopg@arkaria.postgresql.org; Thu, 21 Oct 2021 12:00:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mdWkE-00011L-O9 for psycopg@arkaria.postgresql.org; Thu, 21 Oct 2021 12:00:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mdWkE-00011A-Hu for psycopg@lists.postgresql.org; Thu, 21 Oct 2021 12:00:26 +0000 Received: from mail-vk1-xa29.google.com ([2607:f8b0:4864:20::a29]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mdWkB-0003oD-S7 for psycopg@postgresql.org; Thu, 21 Oct 2021 12:00:26 +0000 Received: by mail-vk1-xa29.google.com with SMTP id 34so122232vkl.13 for ; Thu, 21 Oct 2021 05:00:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nybUxh5TFPleFVmGMpEm04Y0I53ZfcupvRjJePoGwd0=; b=PVVH98jdIZBn6zRcZbEowbw2wWAOA/IH4Qxs/MUBkbQTCAfwo/4OrhooUHnz2Wyu7K K39tIZSXt8ZeB9eShpQRjmlq/2AmZ5KHBur9Xtc/Aq1IOYWIw3iZw7BQlgvdjWTh7Xhl rm7cSA4oxkq0FznLGBr35/qPf6i7NOF7Kkcyag2hXGtC82ZAZ32gpiSeQeYdQ27JDZ1D 30IY3di01js/XI805diwgh5RwG8x3X4WLzfUk8hS6f+/Ig8dCnbWjj2TYFiHNSuck/4t La6yD5kQf1BBSgHtBfjw36Cn4G5kzpkakcDW8hZyYkKjK/LGE0Fi+Nn3Dl1tKsGjrA1F Tthg== 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=nybUxh5TFPleFVmGMpEm04Y0I53ZfcupvRjJePoGwd0=; b=1pnIbUM0S+wMKY3TQBPCwpdOu9i5OPpTkMyWmL0tcavb9BLQJRSraLc9r8bEebmX3k KLlguLYbjeaxoPzqTox0XrX2+N7DMVhXrPQrIm6GjCqVkutroujIJ08QTzsnde9tf6Vs ugmUXMQFG2xV5XG748KctQHWdh0N3wx5ocAIVgYxEsejc+in5Dm9XVpIItfMggxo7g1Y re9zjUMmZO1ynsteBQY3fTpP0Q6NW6XH9cBBFwI6A0L/nibZlecxp1p32FZIRRwXw3Ru yjdbyBagvPSeh7Do4KorblnlRVsFYLIvXrGZmGo2FUCG8SPJpBPX1dcgyBDVLepfrNZq Dfng== X-Gm-Message-State: AOAM532i/pJIpHWxoETZl/jNAiA+zsPGGNrB1FzMQUE1CdM5Amsq+6iQ CM34kPnF8iQ5Sf1TieVWvocboMK4Fj+aA2MhKYM= X-Google-Smtp-Source: ABdhPJyWOl7vB5TE1APnVKEEmdwBk+yGs1y549NHm/Mn574puhdBHHJ6I+hxRr0XJc8PuMbIJUq8deJcJEqGShocuFQ= X-Received: by 2002:a05:6122:1213:: with SMTP id v19mr5007657vkc.2.1634817622301; Thu, 21 Oct 2021 05:00:22 -0700 (PDT) MIME-Version: 1.0 References: <9a99d2d110b121542d1ea0a05066858b@paolodestefani.it> <6683df3e65fe961aa478e61db7ad687d@paolodestefani.it> In-Reply-To: From: Daniele Varrazzo Date: Thu, 21 Oct 2021 13:00:10 +0100 Message-ID: Subject: Re: Re: psycopg3 transactions To: Karsten Hilbert Cc: Paolo De Stefani , Psycopg Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 21 Oct 2021 at 12:06, Karsten Hilbert wrote: > > > The behaviour of a dbapi connection, without context block, is to just close the communication. The fact that this results in a rollback > stems only from the behaviour of the server > > But that's the whole point? A driver should _not_ (by default) alter the default > behaviour of the other end, IMO, without extremely good reason. There _is_ good > reason for the transaction context manager, but not for the connection context > manager or plain use. The implicit BEGIN is also a surprising change from the "natural course of events". Psycopg can still be used as a driver and not alter the natural course of events. I have extended the documentation (https://www.psycopg.org/psycopg3/docs/basic/usage.html#connection-context) both highlighting the difference in behaviour you reported and suggesting to not use 'with' in case more control is needed (using psycopg more as a driver than as the end user). > > asking that the program to 'conn.commit()' explicitly seems an unrequested, kinda ritual, final blessing. > > Exactly. > > > Sending an explicit ROLLBACK is an occurrence much more rare, > > Exactly, and thusly easily forgotten, with possibly dire consequences > (in the case of default-commit, as opposed to default-rollback). On this I disagree. People forget to do things when they are a repetitive common occurrence, not when they are extraordinary. I don't really see a disaster occurring there, especially because porting code from psycopg2 results in pretty much the same operations. -- Daniele