From: Marti Raudsepp <marti@juffo.org>
To: Greg Smith <greg@2ndquadrant.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Euler Taveira de Oliveira <euler@timbira.com>
Cc: pgsql-docs <pgsql-docs@postgresql.org>
Subject: Re: [PATCH] Fix documentation about PL/Python exception handling
Date: Fri, 19 Nov 2010 10:35:11 +0200
Message-ID: <AANLkTimjepOQL1Mj_SdX-cSoXE+d3_RELgpjf87qtuw4@mail.gmail.com> (raw)
In-Reply-To: <4CE5EF2E.6040108@2ndquadrant.com>
References: <AANLkTinWJoW2Q1VOtb-EL_XV3iOrKNBedTFfbx_zhED-@mail.gmail.com>
<4CDAA73A.6090409@timbira.com>
<AANLkTikSed65+BL-iwrjKv2isUS-JSwpWVzbH5dAxgAE@mail.gmail.com>
<6240.1289852723@sss.pgh.pa.us>
<4CE5EF2E.6040108@2ndquadrant.com>
On Fri, Nov 19, 2010 at 05:29, Greg Smith <greg@2ndquadrant.com> wrote:
> The open question for this one then is the right way for exceptions to act.
> Marti, since you've looked at this a bit already, any thoughts on what that
> should look like? You initially commented that what happens was surprising,
> but I'm not clear on what you expected to happen instead.
The documented behavior would make a lot more sense.
For instance, currently, when you call plpy.error(), the exception
that's thrown can be caught, but even if you handle it, the function
still ends up failing. Similarly you CANNOT handle SQL errors -- at
all! All errors are fatal.
CREATE FUNCTION foo() RETURNS text
AS
'try:
plpy.execute("SELECT syntax error")
except:
plpy.notice("exception caught but cannot ignore")
return "retval"
'
LANGUAGE plpythonu;
WARNING: PL/Python: plpy.SPIError: unrecognized error in PLy_spi_execute_query
CONTEXT: PL/Python function "foo"
NOTICE: exception caught but cannot ignore
CONTEXT: PL/Python function "foo"
ERROR: column "syntax" does not exist
LINE 1: SELECT syntax error
^
QUERY: SELECT syntax error
CONTEXT: PL/Python function "foo"
Notice how the return value in the above is ignored, although the
NOTICE is still output. Any new exceptions raised in the exception
handler -- such as coding errors -- are also silently ignored.
Another surprise is that plpy.Error and plpy.Fatal are just empty
exception subclasses -- they behave nothing like
plpy.error()/plpy.fatal(). Since they're normal Python exceptions,
they can be caught and silenced. But an unhandled plpy.Fatal still
results in an ERROR level message, go figure.
I'm surprised that PL/Python got merged into Postgres at all without
proper error handling.
Regards,
Marti
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-docs@postgresql.org
Cc: marti@juffo.org, greg@2ndquadrant.com, tgl@sss.pgh.pa.us, euler@timbira.com
Subject: Re: [PATCH] Fix documentation about PL/Python exception handling
In-Reply-To: <AANLkTimjepOQL1Mj_SdX-cSoXE+d3_RELgpjf87qtuw4@mail.gmail.com>
References: <AANLkTinWJoW2Q1VOtb-EL_XV3iOrKNBedTFfbx_zhED-@mail.gmail.com> <4CDAA73A.6090409@timbira.com> <AANLkTikSed65+BL-iwrjKv2isUS-JSwpWVzbH5dAxgAE@mail.gmail.com> <6240.1289852723@sss.pgh.pa.us> <4CE5EF2E.6040108@2ndquadrant.com> <AANLkTimjepOQL1Mj_SdX-cSoXE+d3_RELgpjf87qtuw4@mail.gmail.com>
* 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