pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexander Lakhin <exclusion@gmail.com>
To: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18070: Assertion failed when processing error from plpy's iterator
Date: Fri, 15 Sep 2023 20:00:00 +0300
Message-ID: <9fa9c154-d084-07de-8224-aab7fc8a119e@gmail.com> (raw)
In-Reply-To: <18070-ab9c171cbf4ebb0f@postgresql.org>
References: <18070-ab9c171cbf4ebb0f@postgresql.org>

25.08.2023 17:00, PG Bug reporting form wrote:
> The following bug has been logged on the website:
>
> Bug reference:      18070
> ...
> It looks like the following coding in PLy_elog_impl():
> 		/* 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;
>
> doesn't expect to process a call PLy_elog(LEVEL, "message") when some (SPI)
> error occurred before the call.
>

Please look at the patch attached, which removes the Assert and changes
the detail message e.g. , for the query:
CREATE EXTENSION plpython3u;
CREATE TYPE tst AS (t text);
CREATE FUNCTION pyfunc() RETURNS SETOF text AS $$
   plan = plpy.prepare("SELECT * FROM tst", ["text"])
   for row in plpy.cursor(plan, ["w"]):
     yield row[0]
$$ LANGUAGE plpython3u;

SELECT pyfunc();

From:
ERROR:  error fetching next item from iterator
LINE 1: SELECT * FROM tst
                       ^
DETAIL:  spiexceptions.WrongObjectType: cannot open relation "tst"
QUERY:  SELECT * FROM tst
CONTEXT:  Traceback (most recent call last):
PL/Python function "pyfunc"

To:
ERROR:  error fetching next item from iterator
LINE 1: SELECT * FROM tst
                       ^
DETAIL:  This operation is not supported for composite types.
QUERY:  SELECT * FROM tst
CONTEXT:  Traceback (most recent call last):
PL/Python function "pyfunc"

Best regards,
Alexander

Attachments:

  [text/x-patch] fix-plpy_elog.patch (645B, ../9fa9c154-d084-07de-8224-aab7fc8a119e@gmail.com/2-fix-plpy_elog.patch)
  download | inline diff:
diff --git a/src/pl/plpython/plpy_elog.c b/src/pl/plpython/plpy_elog.c
index 7c627eacfb..69359908f8 100644
--- a/src/pl/plpython/plpy_elog.c
+++ b/src/pl/plpython/plpy_elog.c
@@ -103,11 +103,11 @@ 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)
+		/*
+		 * When we have no detail from the error data, an exception message,
+		 * if not empty, goes in the detail.
+		 */
+		if (detail == NULL && xmsg != NULL)
 			detail = xmsg;
 	}
 	else


view thread (15+ messages)  latest in thread

Message-ID: <9fa9c154-d084-07de-8224-aab7fc8a119e@gmail.com>
Permalink:  ../9fa9c154-d084-07de-8224-aab7fc8a119e@gmail.com/
Also on:    postgresql.org/message-id/9fa9c154-d084-07de-8224-aab7fc8a119e@gmail.com

 ·  · 

reply

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: exclusion@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #18070: Assertion failed when processing error from plpy's iterator
  In-Reply-To: <9fa9c154-d084-07de-8224-aab7fc8a119e@gmail.com>

* 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