mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-04 09:07:21 +02:00
Fix assertion failure with PL/Python exceptions
PLy_elog() was not able to handle correctly cases where a SPI called
failed, which would fill in a DETAIL string able to trigger an
assertion. We may want to improve this infrastructure so as it is able
to provide any extra detail information provided by an error stack, but
this is left as a future improvement as it could impact existing error
stacks and any applications that depend on them. For now, the assertion
is removed and a regression test is added to cover the case of a failure
with a detail string.
This problem exists since 2bd78eb8d5
, so backpatch all the way down
with tweaks to the regression tests output added where required.
Author: Alexander Lakhin
Discussion: https://postgr.es/m/18070-ab9c171cbf4ebb0f@postgresql.org
Backpatch-through: 11
This commit is contained in:
parent
ec693a3f30
commit
f171430f08
@ -445,3 +445,16 @@ PL/Python function "notice_outerfunc"
|
|||||||
1
|
1
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
/* test error logged with an underlying exception that includes a detail
|
||||||
|
* string (bug #18070).
|
||||||
|
*/
|
||||||
|
CREATE FUNCTION python_error_detail() RETURNS SETOF text AS $$
|
||||||
|
plan = plpy.prepare("SELECT to_date('xy', 'DD') d")
|
||||||
|
for row in plpy.cursor(plan):
|
||||||
|
yield row['d']
|
||||||
|
$$ LANGUAGE plpython3u;
|
||||||
|
SELECT python_error_detail();
|
||||||
|
ERROR: error fetching next item from iterator
|
||||||
|
DETAIL: spiexceptions.InvalidDatetimeFormat: invalid value "xy" for "DD"
|
||||||
|
CONTEXT: Traceback (most recent call last):
|
||||||
|
PL/Python function "python_error_detail"
|
||||||
|
@ -445,3 +445,16 @@ PL/Python function "notice_outerfunc"
|
|||||||
1
|
1
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
/* test error logged with an underlying exception that includes a detail
|
||||||
|
* string (bug #18070).
|
||||||
|
*/
|
||||||
|
CREATE FUNCTION python_error_detail() RETURNS SETOF text AS $$
|
||||||
|
plan = plpy.prepare("SELECT to_date('xy', 'DD') d")
|
||||||
|
for row in plpy.cursor(plan):
|
||||||
|
yield row['d']
|
||||||
|
$$ LANGUAGE plpython3u;
|
||||||
|
SELECT python_error_detail();
|
||||||
|
ERROR: error fetching next item from iterator
|
||||||
|
DETAIL: spiexceptions.InvalidDatetimeFormat: invalid value "xy" for "DD"
|
||||||
|
CONTEXT: Traceback (most recent call last):
|
||||||
|
PL/Python function "python_error_detail"
|
||||||
|
@ -103,9 +103,6 @@ PLy_elog_impl(int elevel, const char *fmt,...)
|
|||||||
}
|
}
|
||||||
primary = emsg.data;
|
primary = emsg.data;
|
||||||
|
|
||||||
/* Since we have a format string, we cannot have a SPI detail. */
|
|
||||||
Assert(detail == NULL);
|
|
||||||
|
|
||||||
/* If there's an exception message, it goes in the detail. */
|
/* If there's an exception message, it goes in the detail. */
|
||||||
if (xmsg)
|
if (xmsg)
|
||||||
detail = xmsg;
|
detail = xmsg;
|
||||||
|
@ -344,3 +344,14 @@ $$ LANGUAGE plpython3u;
|
|||||||
\set SHOW_CONTEXT always
|
\set SHOW_CONTEXT always
|
||||||
|
|
||||||
SELECT notice_outerfunc();
|
SELECT notice_outerfunc();
|
||||||
|
|
||||||
|
/* test error logged with an underlying exception that includes a detail
|
||||||
|
* string (bug #18070).
|
||||||
|
*/
|
||||||
|
CREATE FUNCTION python_error_detail() RETURNS SETOF text AS $$
|
||||||
|
plan = plpy.prepare("SELECT to_date('xy', 'DD') d")
|
||||||
|
for row in plpy.cursor(plan):
|
||||||
|
yield row['d']
|
||||||
|
$$ LANGUAGE plpython3u;
|
||||||
|
|
||||||
|
SELECT python_error_detail();
|
||||||
|
Loading…
Reference in New Issue
Block a user