From: Michael Paquier <michael@paquier.xyz>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Alexander Lakhin <exclusion@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18070: Assertion failed when processing error from plpy's iterator
Date: Sun, 17 Sep 2023 10:50:36 +0900
Message-ID: <ZQZbbPA7NC5A0f4i@paquier.xyz> (raw)
In-Reply-To: <3984911.1694908923@sss.pgh.pa.us>
References: <18070-ab9c171cbf4ebb0f@postgresql.org>
<9fa9c154-d084-07de-8224-aab7fc8a119e@gmail.com>
<ZQVm8KponTxqj8G3@paquier.xyz>
<3920993.1694874885@sss.pgh.pa.us>
<5eba3ea5-ae13-aab2-35d6-cd3e58dab08b@gmail.com>
<ZQY/Nfv20tt4PBzA@paquier.xyz>
<3984911.1694908923@sss.pgh.pa.us>
On Sat, Sep 16, 2023 at 08:02:03PM -0400, Tom Lane wrote:
> +1. Not very sure what we want to change this to in HEAD, but
> I wouldn't backpatch a behavioral change here.
Please find attached a proposal of patch for a backpatch, that applies
on HEAD. The backpatch needs a few tweaks for alternate outputs, of
course, depending on the version of python.
Any thoughts?
--
Michael
Attachments:
[text/x-diff] v3-01-fix-plpy_elog.patch (2.8K, ../ZQZbbPA7NC5A0f4i@paquier.xyz/2-v3-01-fix-plpy_elog.patch)
download | inline diff:diff --git a/src/pl/plpython/expected/plpython_error.out b/src/pl/plpython/expected/plpython_error.outindex 9af7ea7292..77819cb416 100644--- a/src/pl/plpython/expected/plpython_error.out+++ b/src/pl/plpython/expected/plpython_error.out@@ -445,3 +445,16 @@ PL/Python function "notice_outerfunc"
1
(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('DD', '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 "DD" for "DD"+CONTEXT: Traceback (most recent call last):+PL/Python function "python_error_detail"diff --git a/src/pl/plpython/expected/plpython_error_5.out b/src/pl/plpython/expected/plpython_error_5.outindex 7fe864a1a5..b1b4eaa375 100644--- a/src/pl/plpython/expected/plpython_error_5.out+++ b/src/pl/plpython/expected/plpython_error_5.out@@ -445,3 +445,16 @@ PL/Python function "notice_outerfunc"
1
(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('DD', '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 "DD" for "DD"+CONTEXT: Traceback (most recent call last):+PL/Python function "python_error_detail"diff --git a/src/pl/plpython/plpy_elog.c b/src/pl/plpython/plpy_elog.cindex 7c627eacfb..70de5ba13d 100644--- a/src/pl/plpython/plpy_elog.c+++ b/src/pl/plpython/plpy_elog.c@@ -103,9 +103,6 @@ PLy_elog_impl(int elevel, const char *fmt,...)
}
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 (xmsg)
detail = xmsg;
diff --git a/src/pl/plpython/sql/plpython_error.sql b/src/pl/plpython/sql/plpython_error.sqlindex 11f14ec5a7..111f62eb27 100644--- a/src/pl/plpython/sql/plpython_error.sql+++ b/src/pl/plpython/sql/plpython_error.sql@@ -344,3 +344,14 @@ $$ LANGUAGE plpython3u;
\set SHOW_CONTEXT always
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('DD', 'DD') d")+ for row in plpy.cursor(plan):+ yield row['d']+$$ LANGUAGE plpython3u;++SELECT python_error_detail();
[application/pgp-signature] signature.asc (832B, ../ZQZbbPA7NC5A0f4i@paquier.xyz/3-signature.asc)
download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: michael@paquier.xyz, tgl@sss.pgh.pa.us, exclusion@gmail.com, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18070: Assertion failed when processing error from plpy's iterator
In-Reply-To: <ZQZbbPA7NC5A0f4i@paquier.xyz>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox