[prev in list] [next in list] [prev in thread] [next in thread]
List: pgsql-bugs
Subject: [BUGS] BUG #11469: Recursive plpython function results in KeyError for next function
From: rahiyer () gmail ! com
Date: 2014-09-22 17:47:15
Message-ID: 20140922174715.17174.44694 () wrigleys ! postgresql ! org
[Download RAW message or body]
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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic