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

Appearance settings

Commit af5b3c3

Browse filesBrowse 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 c103d07 commit af5b3c3
Copy full SHA for af5b3c3

File tree

Expand file treeCollapse file tree

4 files changed

+37
-3
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+37
-3
lines changed

‎src/pl/plpython/expected/plpython_error.out

Copy file name to clipboardExpand all lines: src/pl/plpython/expected/plpython_error.out
+13Lines 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 plpython3u;
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

Copy file name to clipboardExpand all lines: src/pl/plpython/expected/plpython_error_5.out
+13Lines 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 plpython3u;
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

Copy file name to clipboardExpand all lines: src/pl/plpython/plpy_elog.c
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ PLy_elog_impl(int elevel, const char *fmt,...)
103103
}
104104
primary = emsg.data;
105105

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

‎src/pl/plpython/sql/plpython_error.sql

Copy file name to clipboardExpand all lines: src/pl/plpython/sql/plpython_error.sql
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,14 @@ $$ LANGUAGE plpython3u;
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 plpython3u;
356+
357+
SELECT python_error_detail();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.