Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qhgw1-003ugj-VK for pgsql-bugs@arkaria.postgresql.org; Sun, 17 Sep 2023 01:50:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qhgvz-002EQz-QA for pgsql-bugs@arkaria.postgresql.org; Sun, 17 Sep 2023 01:50:51 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qhgvy-002EPr-5M for pgsql-bugs@lists.postgresql.org; Sun, 17 Sep 2023 01:50:51 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qhgvu-004zD7-CA for pgsql-bugs@lists.postgresql.org; Sun, 17 Sep 2023 01:50:48 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 28F265C00AF; Sat, 16 Sep 2023 21:50:44 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Sat, 16 Sep 2023 21:50:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1694915444; x=1695001844; bh=Yq eeeqpJ6mgEpLitIQRtjH2hGCjkdA1joqgnFOOQGWc=; b=tuQhaBDAqZOjAR52AA ZRTDuMD3ZOyQKOSkKPJlJI2noP8yCPrI5yXrgxP025cUmEjHQTtD2EZJIT8FQ1qN 9qhfB4VNvueABDiaDI5Q/UEM03nKDMHV+4ZyBhNCnmUdcyYTQVJkRl7VJOXkDveH 873Is30uiVvvK/Gt+9Q0g3WcT1siFvp4etk73TPF3NSE6Jz+qpDgvY8ousHyx2zh O0ueUKt4erVGXbPrJm/yFURpWAfaeU8dYGbAgQgjRL4mzl5kuedc+Pf/wmCWwoqf 85R0E/F9eeg1zKhBMeVb4DGsSIsxSY7ewzpbiLNs3pGJf/BChnU+WrIIps7w2Z/H gweA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1694915444; x=1695001844; bh=YqeeeqpJ6mgEp LitIQRtjH2hGCjkdA1joqgnFOOQGWc=; b=Tl69iUZl5vq0y7QHTjfRd9LC52kPo VCGy2bWeHTifj7HkMsbtRmS8oqyN3x2y5COi8BZTd52yYibLp4TVTSJftVGpmX68 i2O/tU2QuntMqwRKB4kijaM5iP6l97fImcyC4Wzzm3QL40TTDZOjA70Z0b0Z6NEW ku3QzwIfNbo/QzViVawLPtSb7YKoTkXv3HRQkR/CrJk9m4paxUmtl5nXwzIbMTPr THAIozvzgBxtQlD/IUMRuQYff4knN0YdIn2m7bNb0yAXNIWHco8bRbmakXMLxnHO PTQ1qDq/IshD9E4DJ41CIo8XawGD1McIoLd7H/njmZhuVhBpD61kSY3mQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudejhedghedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdljedtmdenucfjughrpeffhf fvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefoihgthhgrvghlucfrrghq uhhivghruceomhhitghhrggvlhesphgrqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvg hrnhepteelieefudffhffhtdetleeggeegfffhkeeuveetiefgudduvedutefggeeivdej necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhhitg hhrggvlhesphgrqhhuihgvrhdrgiihii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 16 Sep 2023 21:50:41 -0400 (EDT) Date: Sun, 17 Sep 2023 10:50:36 +0900 From: Michael Paquier To: Tom Lane Cc: Alexander Lakhin , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18070: Assertion failed when processing error from plpy's iterator Message-ID: References: <18070-ab9c171cbf4ebb0f@postgresql.org> <9fa9c154-d084-07de-8224-aab7fc8a119e@gmail.com> <3920993.1694874885@sss.pgh.pa.us> <5eba3ea5-ae13-aab2-35d6-cd3e58dab08b@gmail.com> <3984911.1694908923@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="UYBG0NW/CT5/UQC6" Content-Disposition: inline In-Reply-To: <3984911.1694908923@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --UYBG0NW/CT5/UQC6 Content-Type: multipart/mixed; boundary="InzXz8+PsilnaQ4i" Content-Disposition: inline --InzXz8+PsilnaQ4i Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --InzXz8+PsilnaQ4i Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-01-fix-plpy_elog.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/pl/plpython/expected/plpython_error.out b/src/pl/plpython/= expected/plpython_error.out index 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) =20 +/* test error logged with an underlying exception that includes a detail + * string (bug #18070). + */ +CREATE FUNCTION python_error_detail() RETURNS SETOF text AS $$ + plan =3D 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/plpytho= n/expected/plpython_error_5.out index 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) =20 +/* test error logged with an underlying exception that includes a detail + * string (bug #18070). + */ +CREATE FUNCTION python_error_detail() RETURNS SETOF text AS $$ + plan =3D 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.c index 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 =3D emsg.data; =20 - /* Since we have a format string, we cannot have a SPI detail. */ - Assert(detail =3D=3D NULL); - /* If there's an exception message, it goes in the detail. */ if (xmsg) detail =3D xmsg; diff --git a/src/pl/plpython/sql/plpython_error.sql b/src/pl/plpython/sql/p= lpython_error.sql index 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 =20 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 =3D plpy.prepare("SELECT to_date('DD', 'DD') d") + for row in plpy.cursor(plan): + yield row['d'] +$$ LANGUAGE plpython3u; + +SELECT python_error_detail(); --InzXz8+PsilnaQ4i-- --UYBG0NW/CT5/UQC6 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmUGW2wACgkQnvQgOdby QH0D/w//aivUTAEL+ESyME/DqGjUoGPo5eydSWo6/JAV1YiOPBew76q32WmRZER9 6tr8ohfq+OvNTauwOKLgsdkLnlTU+dmzBMn+jSz252Tu56mCL8lVsLWggHjzfzPD 1fwJzf36TMIogckD9w75gRkJe5X5dR0Ejh/k4tMhmiQHgxLXCIDEPQEJDzqaeWCM NrsLVgIAcDaOrvNGwzadCs2aC9ZSbBXbQvrPMWPzrnuDJ0jqhXovNTQcItcYlRej 0S5LvzuUvmQ1NlLqms0BoUliy1Mx7I7Crf4AkgPUXBs6OsJ504bwVgMxX3rX8ChG h+AocvZbjWCNePKby5I1DWKLj8YjAcAPyY7sbHsh1o43T8lhjUDSsWTofJ7dOVqo PZO+GgtZPH7FrFXFNYUrgt6engjcUPu6rhTRqxzY0XNQLmqA9csg4kPmryVocywV jN5JZWxWNr3oZz3Xc1ID+AD3KS21wCrwh5/Y2duBXBN1li7Xm0iwRufQ5fYpG0fP phtNJtxz3dWGOlbCLfFKwrKZxOVEF9nN+jTVEs92YZJjHroDrAtpE0kGvbwmnV0R 82QOaj9cguG8Sf5assCstuplCQwd7yLbYzoC4PVXJSU+fs64vdk4dGCVm13OXwFg CxX3ZInptmjlz5EnGIFDGhn9mwjDvav++cG0l0G2YsipiRUxsbE= =t8gw -----END PGP SIGNATURE----- --UYBG0NW/CT5/UQC6--