Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit99d27e5

Browse files
committed
Fix assertion failure with PL/Python exceptions
PLy_elog() was not able to handle correctly cases where a SPI calledfailed, which would fill in a DETAIL string able to trigger anassertion. We may want to improve this infrastructure so as it is ableto provide any extra detail information provided by an error stack, butthis is left as a future improvement as it could impact existing errorstacks and any applications that depend on them. For now, the assertionis removed and a regression test is added to cover the case of a failurewith a detail string.This problem exists since2bd78eb, so backpatch all the way downwith tweaks to the regression tests output added where required.Author: Alexander LakhinDiscussion:https://postgr.es/m/18070-ab9c171cbf4ebb0f@postgresql.orgBackpatch-through: 11
1 parent1233370 commit99d27e5

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
@@ -107,9 +107,6 @@ PLy_elog_impl(int elevel, const char *fmt,...)
107107
}
108108
primary=emsg.data;
109109

110-
/* Since we have a format string, we cannot have a SPI detail. */
111-
Assert(detail==NULL);
112-
113110
/* If there's an exception message, it goes in the detail. */
114111
if (xmsg)
115112
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+
CREATEFUNCTIONpython_error_detail() RETURNS SETOFtextAS $$
352+
plan=plpy.prepare("SELECT to_date('xy', 'DD') d")
353+
for rowinplpy.cursor(plan):
354+
yield row['d']
355+
$$ LANGUAGE plpythonu;
356+
357+
SELECT python_error_detail();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp