plPython and restricted execution issues

From: Jean-Christophe ARNU (JX) <arnu(at)paratronic(dot)fr>
To: pgsql-general(at)postgresql(dot)org
Subject: plPython and restricted execution issues
Date: 2003-07-25 09:23:29
Message-ID: 20030725112329.5c05cb0e.arnu@paratronic.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi.

I've made a small stored procedure un PL/python. This procedure retrieve
python code from a row then execute it and calls a predefined function.
Alls works well while no others functions are defined and called in the row
retrieved code; I mean when I define the row retrieved code like this :

def powar(x):
return x*x

def make_transform(x,y):
plpy.notice("viewed from make_transform : %s"%out)
if x>2 and y >5:
return powar(x+y)
else:
return x+y

and when I execute the following python stored procedure:

CREATE OR REPLACE FUNCTION tarage(NUMERIC,NUMERIC) RETURNS NUMERIC AS'
qry = plpy.prepare("SELECT expression from fonctions where name = $1",
["text"])
res = plpy.execute(qry,["transf(x,y)"])
expression = res[0]["expression"]
x=args[0]
y=args[1]
plpy.notice(expression)
exec expression
out = "%s"%dir()
plpy.notice(out)
b = make_transform(x,y)
return b
'
LANGUAGE 'plpython';

Here is the output :

supervisor=# select tarage(4.0,2.0);
NOTICE: ('\ndef powar(f):\n\treturn f*f\n\ndef make_transform(x,y):\n\tout =
"%s"%dir()\n\tplpy.notice("viewed from make_transform : %s"%out)\n\tif
x>2:\n\t\treturn powar(x)\n\telse:\n\t\treturn x+y\n',)
NOTICE: ("['expression', 'make_transform', 'powar', 'qry', 'res', 'x',
'y']",)
NOTICE: ("viewed from make_transform : ['x', 'y']",)
ERROR: plpython: Call of function `tarage' failed.
exceptions.NameError: global name 'powar' is not defined

Well, I tried to recreate the restricted execution env, in my python console
interpreter and I got the right result!

So is there a way to get the whole things work (to make powar() visible from
make_transform())?

Thanks in advance?

--
Jean-Christophe ARNU

Browse pgsql-general by date

  From Date Subject
Next Message Tim McAuley 2003-07-25 10:44:53 casting timeofday() to timestamp boken under cygwin - Problem identified
Previous Message Nagy Karoly 2003-07-25 08:02:11 PostgreSQL authentication