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 1mbsU3-00013G-3i for psycopg@arkaria.postgresql.org; Sat, 16 Oct 2021 22:48:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mbsU1-0002bE-Lj for psycopg@arkaria.postgresql.org; Sat, 16 Oct 2021 22:48:53 +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 1mbsU1-0002b5-Fg for psycopg@lists.postgresql.org; Sat, 16 Oct 2021 22:48:53 +0000 Received: from mout.gmx.net ([212.227.17.21]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mbsTu-0004Tk-OB for psycopg@postgresql.org; Sat, 16 Oct 2021 22:48:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1634424522; bh=C8MkfhspecVQZbqAqhxnRW3RTqj2NFAXGbBARz8G+rk=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:References:In-Reply-To; b=A59Jay0Z6I9/xOkfg7xkuid3tWWNbQICRxvSU9DZg2bdDeHWyAFnhXT9qjovjRgvE SmJCVvZDWeINNneXEg9Q9FgAmbxlSyH+9nfVjrEm7MyUOqKtDBrSp++koy/0gv3RS2 LTC+f//f7SHRZQtoDZvGDapPBSFa0JDvF4mehp6c= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from hermes ([77.11.30.125]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N9MpY-1mqG3336f6-015LpU; Sun, 17 Oct 2021 00:48:42 +0200 Received: from ncq by hermes with local (Exim 4.94.2) (envelope-from ) id 1mbsTo-0001Zd-4t; Sun, 17 Oct 2021 00:48:40 +0200 Date: Sun, 17 Oct 2021 00:48:40 +0200 From: Karsten Hilbert To: Daniele Varrazzo Cc: Paolo De Stefani , Psycopg Subject: Re: psycopg3 transactions Message-ID: Mail-Followup-To: Daniele Varrazzo , Paolo De Stefani , Psycopg References: <9a99d2d110b121542d1ea0a05066858b@paolodestefani.it> <6683df3e65fe961aa478e61db7ad687d@paolodestefani.it> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: Ma_X_il-Followup-to: d Re_X_turn-receipt-to: Karsten.Hilbert@gmx.net Di_X_sposition-Notification-To: Karsten.Hilbert@gmx.net X-Confi_X_rm-Reading-To: Karsten.Hilbert@gmx.net X-Pri_X_ority: 2 (High) Sender: X-Provags-ID: V03:K1:tTckr1UKVLdbM1wWiLIlRKpVzcIBmzW4onkGUhPO6N/Ue4fHZnY YNw4qKqZ4o+uvW92BCeXAQVOzr9WPIlDcuWCgofFGqDIMKaw75ROFbYUeG9kkhPy1cN2D4j VMsSMkKtwMOkggeaqiFCWQjQ4bRylAY7ukzaJTlqzOF5+xA54gJ5dA7UTwRaU0xwIjyj9Ra PMTPIXefmaPtf3LTeSbyA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:RTI6NnJsMJ8=:RG4EoRKZSG4sdbKrg/r0qE B3hQlrJ8+7NZk4Sh75R0GFE2QwDS8u+ESKvV8JjTMdOH9pYtUYW9V/fh1CtJYBNCsfFtJ1Hto wy6T0jXCpe4IIOE7Udfb0dsSgb3i/StBQ+Vcl5DLv3Gvy6aJ2GhSsRYmtfNyFMOohoHi0Ef8a W0T30kW5Uuo+U36ISlJ3ciDnFHZsQscR0t1Mmds/A4U+juRfTZhfm9UPEn0nukSKrGZw03vMI pHYLaVHuARveR4M0TWbv+6eq7aaWQfDQ3I69OFvbQeOsYLwjMBSNbU5I/gFQ6CY+lFUk7Bral /5i3TJIEaPJkQytyzJ32uGfxkpfi6do0VXFWCgkoBLRsKNxKFBZe+QiDjnNlQ/iO/4VWJcRzj +nouW6/GlPjXkktbDnz2DAmxaUFP9yFJ/T5LA7d+nKBMbN9KO07zhZzIa6WAnyBqGy2H+bt4G qoF/tpCkPkSA180bxOF+NplgR4JicA76yyLwPkMJO6c4gz7enjp7bGWqW/sbewYnvTBFxwq3V pdBc+0k6F6UFW3JJtHft0izf0Di0kxLXoZKJ4E4/m4+xaC70JJVJ5ljTzp150u2LUCEZ+BCZ+ KH3wxkLIFd5hdfXE0V6UXKyFzfrWPfknS76u8XvStZi4DhCLlpwmjNGFWGg3GUDirT3KWnZUl RgjRbixtsvW/ulxzVO1TmTAyZXla/sWUJEGbzs2L02lsX7aM9aLW/VudYTTnukwOaRlIEqQQx iF0Hlr0m6r7FJpdURvPIOkIUeOeHbkbt7g+UeULNrlIfJiwZAsudwt8nPs9Q6HJJP6UtgSV9Z NbzgStPQB1VcZRzk3AbyFbOWEBHb86ULcoLnWkGgKplHis/bZomQSERY1Rk7Rla0c41ZHGmKJ ZoN7nz7VkrznX1bq3yVmOWuV59nDtTUaVqx1MwMhStDxnYdoEzSGzWXvvtdQ6K+ABUCaCmaSI MP9MCWjxocsevBmn5uU5gk4802wJQ0Z0vZaOnRPc7/J7CajhlhEbQPVYHQUxsMMeARydGHO1y 9xnND11gPKh4dQgtEvrIEHDvkEsmDLnJ6pPpKDuPbtwXnJkF4ROZgfbjLZuSeNbQ4C/MlfwiM NbbD+dDfU+1kaQ= List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > I have expanded the documentation about transaction behaviour. > Feedback is welcome. > > 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 agree that writing to files seems similar, and is persistent by default, but then files don't sport transaction semantics. I also agree that a transaction being started by the first SQL command can be surprising to newcomers. It could be explained away by stating "once you start doing something to the database you *are* inside a transaction -- unless you have taken very specific action not to be" very prominently in the docs. However, the fact that "plain" use of psycopg3 and context manager use of psycopg3 yields opposite behaviour (default-rollback vs default-commit) seems to violate the Principle Of Least Astonishment ? Best, Karsten =2D- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B