From: rahiyer@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #11469: Recursive plpython function results in KeyError for next function
Date: Mon, 22 Sep 2014 17:47:15 +0000
Message-ID: <20140922174715.17174.44694@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
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 <module>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: rahiyer@gmail.com
Subject: Re: BUG #11469: Recursive plpython function results in KeyError for next function
In-Reply-To: <20140922174715.17174.44694@wrigleys.postgresql.org>
References: <20140922174715.17174.44694@wrigleys.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox