8000 Fix assertion failure with PL/Python exceptions · postgres/postgres@ddded77 · GitHub
[go: up one dir, main page]

Skip to content

Commit ddded77

Browse files
committed
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 2bd78eb, 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
1 parent db00be6 commit ddded77

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

src/pl/plpython/expected/plpython_error.out

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,3 +445,16 @@ PL/Python function "notice_outerfunc"
445445
1
446446
(1 row)
447447

448+
/* test error logged with an underlying exception that includes a detail
449+
* string (bug #18070).
450+
*/
451+
CREATE FUNCTION python_error_detail() RETURNS SETOF text AS $$
452+
plan = plpy.prepare("SELECT to_date('xy', 'DD') d")
453+
for row in plpy.cursor(plan):
454+
yield row['d']
455+
$$ LANGUAGE plpythonu;
456+
SELECT python_error_detail();
457+
ERROR: error fetching next item from iterator
458+
DETAIL: spiexceptions.InvalidDatetimeFormat: invalid value "xy" for "DD"
459+
CONTEXT: Traceback (most recent call last):
460+
PL/Python function "python_error_detail"

src/pl/plpython/expected/plpython_error_0.out

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,3 +445,16 @@ PL/Python function "notice_outerfunc"
445445
1
446446
(1 row)
447447

448+
/* test error logged with an underlying exception that includes a detail
449+
* string (bug #18070).
450+
*/
451+
CREATE FUNCTION python_error_detail() RETURNS SETOF text AS $$
452+
plan = plpy.prepare("SELECT to_date('xy', 'DD') d")
453+
for row in plpy.cursor(plan):
454+
yield row['d']
455+
$$ LANGUAGE plpythonu;
456+
SELECT python_error_detail();
457+
ERROR: error fetching next item from iterator
458+
DETAIL: spiexceptions.InvalidDatetimeFormat: invalid value "xy" for "DD"
459+
CONTEXT: Traceback (most recent call last):
460+
PL/Python function "python_error_detail"

src/pl/plpython/expected/plpython_error_5.out

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,3 +445,16 @@ PL/Python function "notice_outerfunc"
445445
1
446446
(1 row)
447447

448+
/* test error logged with an underlying exception that includes a detail
449+
* string (bug #18070).
450+
*/
451+
CREATE FUNCTION python_error_detail() RETURNS SETOF text AS $$
452+
plan = plpy.prepare("SELECT to_date('xy', 'DD') d")
453+
for row in plpy.cursor(plan):
454+
yield row['d']
455+
$$ LANGUAGE plpythonu;
456+
SELECT python_error_detail();
457+
ERROR: error fetching next item from iterator
458+
DETAIL: spiexceptions.InvalidDatetimeFormat: invalid value "xy" for "DD"
459+
CONTEXT: Traceback (most recent call last):
460+
PL/Python function "python_error_detail"

src/pl/plpython/plpy_elog.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@ PLy_elog_impl(int elevel, const char *fmt,...)
105105
}
106106
primary = emsg.data;
107107

108-
/* Since we have a format string, we cannot have a SPI detail. */
109-
Assert(detail == NULL);
110-
111108
/* If there's an exception message, it goes in the detail. */
112109
if (xmsg)
113110
detail = xmsg;

src/pl/plpython/sql/plpython_error.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,14 @@ $$ LANGUAGE plpythonu;
344344
\set SHOW_CONTEXT always
345345

346346
SELECT notice_outerfunc();
347+
348+
/* test error logged with an underlying exception that includes a detail
349+
* string (bug #18070).
350+
*/
351+
CREATE FUNCTION python_error_detail() RETURNS SETOF text AS $$
352+
plan = plpy.prepare("SELECT to_date('xy', 'DD') d")
353+
for row in plpy.cursor(plan):
354+
yield row['d']
355+
$$ LANGUAGE plpythonu;
356+
357+
SELECT python_error_detail();

0 commit comments

Comments
 (0)
0