plPython and restricted execution issues - Mailing list pgsql-general

From Jean-Christophe ARNU (JX)
Subject plPython and restricted execution issues
Date
Msg-id 20030725112329.5c05cb0e.arnu@paratronic.fr
Whole thread Raw
List 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

pgsql-general by date:

Previous
From: Thomas Kellerer
Date:
Subject: Re: Which file belongs to which database?
Next
From: Andrew Sullivan
Date:
Subject: Re: Can I turn the case sensitive off