Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s3KDj-00Br9d-K2 for pgsql-bugs@arkaria.postgresql.org; Sat, 04 May 2024 18:34:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1s3KDg-001Vqe-Av for pgsql-bugs@arkaria.postgresql.org; Sat, 04 May 2024 18:34:49 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s3KDf-001VqN-Pj for pgsql-bugs@lists.postgresql.org; Sat, 04 May 2024 18:34:48 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s3KDZ-001RbK-M6 for pgsql-bugs@lists.postgresql.org; Sat, 04 May 2024 18:34:47 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 444IYet72944263; Sat, 4 May 2024 14:34:40 -0400 From: Tom Lane To: jacques@quantsolutions.co.za cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18456: Trigger data in plpython3u trigger-function changes in AFTER UPDATE OR INSERT trigger In-reply-to: <18456-82d3d70134aefd28@postgresql.org> References: <18456-82d3d70134aefd28@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Fri, 03 May 2024 14:37:12 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2944261.1714847680.1@sss.pgh.pa.us> Date: Sat, 04 May 2024 14:34:40 -0400 Message-ID: <2944262.1714847680@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > Then the trigger data changes after the insert statement in the trigger > function. Hmm. TD is defined as a global dictionary like SD, so it saves values across calls to the plpython function. So the inner INSERT operation fires the same trigger, which decides not to print anything, but nonetheless it's changed TD and the outer trigger call will see that. There used to be similar problems in plain plpython functions if they were invoked recursively, because named function arguments are also passed as global variables. We fixed that in a rather hacky way in 1d2fe56e4, ie save and restore those globals when recursing. Probably the same thing could be done with TD. regards, tom lane