SPI_ERROR_UNCONNECTED in python callback function

From: Ian Haywood <ihaywood(at)iinet(dot)net(dot)au>
To: pgsql-general(at)postgresql(dot)org
Subject: SPI_ERROR_UNCONNECTED in python callback function
Date: 2009-06-03 11:12:03
Message-ID: 200906032112.03690.ihaywood@iinet.net.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I am using PL/Python to make queries via SPI. This seems to work when the
query is made directly, but when I pass a function as a callback to an external
module (in this case, python's cheetah templating engine), the function fails thusly:

=# select common.template(8963,1);
ERROR: plpython: function "template" could not create return value
DETAIL: <class 'plpy.SPIError'>: SPI_execute failed: SPI_ERROR_UNCONNECTED
=#

The code is

from Cheetah.Template import Template
import os, tempfile

def sql(x):
return plpy.execute(x)[0] # this is the callback function
def row(t,f,v):
return sql("select * from %s where %s = %s" % (t,f,v))
q = row("common.lu_templates","pk",template)
templ = q["definition"]
result = Template(templ, searchList=[{'row':row,'key':key,'plpy':plpy,'GD':GD,'sql':sql}]) # this template is calling the sql function above.
return result

It seems as soon as execution leaves the main function access to SPI is lost. Is this correct or a bug?
Is there any way to re-enable access to SPI?

Postgresql is 8.3.3, Python 2.5.2

Ian

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Geoffrey 2009-06-03 11:38:39 Re: warm standby with WAL shipping
Previous Message Sebastien FLAESCH 2009-06-03 10:07:15 Re: Need for official 0.83 release