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 1mb9Mx-0001NY-Rv for psycopg@arkaria.postgresql.org; Thu, 14 Oct 2021 22:38:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mb9Mw-0004Tf-Jl for psycopg@arkaria.postgresql.org; Thu, 14 Oct 2021 22:38:34 +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 1mb9Mu-0004TW-Od for psycopg@lists.postgresql.org; Thu, 14 Oct 2021 22:38:34 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mb9Mq-0007jO-Hm for psycopg@postgresql.org; Thu, 14 Oct 2021 22:38:32 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 166173200E18; Thu, 14 Oct 2021 18:38:24 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 14 Oct 2021 18:38:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= message-id:date:mime-version:subject:to:references:from :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=o wbOXNRyCOfCmv94SjzxVA208+sVwgFOE9iCm5Jhvr4=; b=KiILZy0xtiYrxsTrX uZRSJfUAg1zcztmO92ZJPF0hQtIYOIO/jwvQMdyMCnMz7+AfUxUNjLsu+wFF2EaD QxFF63CJC/v3xyg68lkJ3vhpZpgJwTCPiZfgZKxmYByalpQtQlkc4XZJUndGcnTG ZwpAds45Y8SiUEpPhZvzzRUEUt4jkI5mGKguKJ7Ako2iBWXdmDUCcJ8S4S2VuXGQ fBx+hDXKovzx0D1msjohHfdSZZ85gI/cy8QeXeZfeB6u7sbCiZPjPGH5ftIG2+pq 1Bopwv+POnDPgPqgQidYr42e4fgouNrkOfkElqnhwQccfO4PKTv+rLQzP4r9+3U8 GHhxw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=owbOXNRyCOfCmv94SjzxVA208+sVwgFOE9iCm5Jhv r4=; b=Pf7Mfz+2jjXMW+Zm2W4tbcRCPwjJTS23izRvQsnmReqJJGunTfI4uOFxr gYwEakQYy5HwNeGN8Xhy4bRNVjroateJcpdVL9RRdf70qAGKuwqUatTyB8qnYu0d Gr6UrP0I96mB38o4VsjtcC9ZdXWvcP2k4ua/GuSwjRZ6b2RYqC3Ib5Cd5IRouBLJ ff09C/fttHapWpAIOjtsHz3kmf/ISPruESnf6yeM+iEoLmL6MOvl4bqDhn2bncr5 Hadk6EnQSeYdCOYsycysWrbnRetlFFjoZAFg9NKwB6F54rs3jF9vZboc/L64IBIE gkQF/k9QkH3KhJUtLz+b3qFXABdoQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrvddufedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvfhfhjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeethefgvedtvedutdejudfgfeffvefgffeludehkeff ffduteevtdelfffhjeduheenucffohhmrghinhepphhshigtohhpghdrohhrghenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdr khhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 14 Oct 2021 18:38:22 -0400 (EDT) Message-ID: Date: Thu, 14 Oct 2021 15:38:21 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: psycopg3 transactions Content-Language: en-US To: Daniel Fortunov , Daniele Varrazzo , Paolo De Stefani , Psycopg References: <9a99d2d110b121542d1ea0a05066858b@paolodestefani.it> From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 10/14/21 15:16, Karsten Hilbert wrote: >> We are still "using transactions", just with more precise, more explicit*, >> and more flexible* semantics, represented by a context manager. >> >> Rolling back a transaction is possible by raising a Rollback exception >> within a block. >> >> I hope this answers your question but if not please describe the scenario >> you are thinking about. > > Personally, I think the autocommit=False approach is somewhat > safer (more conservative) for the data: > > One *always* is inside a transaction, and the default > behaviour is to rollback. > > Nothing is by accident automatically committed -- which can > happen with autocommit=True. +1 > > I would certainly suggest that a context manager calls > .rollback() during teardown rather than .commit() -- the > context manager cannot know whether actions really are to > be committed, even if technically possible. If I'm following that option exists: https://www.psycopg.org/psycopg3/docs/api/connections.html#psycopg.Connection.transaction force_rollback (bool) – Roll back the transaction at the end of the block even if there were no error (e.g. to try a no-op process). > > Karsten > -- > GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B > > -- Adrian Klaver adrian.klaver@aklaver.com