Re: [PATCH] PL/Python: Add spidata to all spiexceptions

From: Jan Urbański <wulczer(at)wulczer(dot)org>
To: Oskari Saarenmaa <os(at)ohmu(dot)fi>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] PL/Python: Add spidata to all spiexceptions
Date: 2012-10-31 09:33:17
Message-ID: 5090F05D.5060507@wulczer.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 30/10/12 22:06, Oskari Saarenmaa wrote:
> PL/Python maps Python SPIError exceptions with 'spidata' attribute into SQL
> errors. PL/Python also creates classes in plpy.spiexceptions for all known
> errors but does not initialize their spidata, so when a PL/Python function
> raises such an exception it is not recognized properly and is always
> reported as an internal error.

You're right, I never thought of the possibility of user code explicitly
throwing SPIError exceptions.

The root issue is that PLy_elog will only set errcode if it finds the
"spidata" attribute, but I think passing error details through that
attribute is a kludge more than something more code should rely on.

Here's an alternative patch that takes advantage of the already present
(and documented) "sqlstate" variable to set the error code when handling
SPIError exceptions.

I also used your test case and added another one, just in case.

Thanks,
Jan

Attachment Content-Type Size
0001-Set-SQL-error-code-for-SPI-errors-raised-from-userla.patch text/x-diff 0 bytes

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Baptiste LHOSTE 2012-10-31 11:25:47 Autoanalyze of the autovacuum daemon ...
Previous Message Pavel Stehule 2012-10-31 09:32:22 state of patch - lock waits stats?