Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XWGPj-0003Wv-Ri for pgsql-bugs@arkaria.postgresql.org; Tue, 23 Sep 2014 03:05:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XWGPi-0005Fb-TX for pgsql-bugs@arkaria.postgresql.org; Tue, 23 Sep 2014 03:05:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XW7iY-00016R-Iy for pgsql-bugs@postgresql.org; Mon, 22 Sep 2014 17:48:06 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XW7iU-0006PA-RJ for pgsql-bugs@postgresql.org; Mon, 22 Sep 2014 17:48:05 +0000 MIME-Version: 1.0 Subject: BUG #11469: Recursive plpython function results in KeyError for next function To: pgsql-bugs@postgresql.org From: rahiyer@gmail.com Date: Mon, 22 Sep 2014 17:47:15 +0000 Message-ID: <20140922174715.17174.44694@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.3 (/) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 11469 Logged by: Rahul Iyer Email address: rahiyer@gmail.com PostgreSQL version: 9.3.5 Operating system: Mac osx 10.9.4 Description: The problem occurs when a plpython function calls itself using plpy.execute. The next plpython function results in a KeyError corresponding to the last argument of the recursive function. The problem does not occur if a string representation of 'globals()' is created. Minimal repro steps have been provided below. ----------------------------------------------- CREATE OR REPLACE FUNCTION recur_test(a int) RETURNS VOID AS $$ if a: plpy.execute("select recur_test({0})".format(a-1)) $$ LANGUAGE PLPYTHONU; CREATE OR REPLACE FUNCTION test() RETURNS TEXT AS $$ import sys return 'test' $$ LANGUAGE PLPYTHONU; CREATE OR REPLACE FUNCTION test2() RETURNS TEXT AS $$ g = str(globals()) import sys return 'test' $$ LANGUAGE PLPYTHONU; ----------------------------------------------- -- Postgres version -- Both functions work as expected # SELECT test(); test ------ test (1 row) # SELECT test2(); test2 ------- test (1 row) -- recursive function call # SELECT recur_test(2); recur_test ------------ (1 row) # SELECT test(); ERROR: XX000: KeyError: 'a' CONTEXT: Traceback (most recent call last): PL/Python function "test", line 2, in import sys PL/Python function "test" LOCATION: PLy_elog, plpy_elog.c:106 -- second call does not give error # SELECT test(); test ------ test (1 row) # SELECT recur_test(2); recur_test ------------ (1 row) -- no error in this case # SELECT test2(); test2 ------- test (1 row) --------------------------------------------------- -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs