Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ps2uI-0004ti-1q for pgsql-bugs@arkaria.postgresql.org; Thu, 27 Apr 2023 14:47:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ps2tH-0005xa-UA for pgsql-bugs@arkaria.postgresql.org; Thu, 27 Apr 2023 14:46:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ps2tH-0005xR-Lj for pgsql-bugs@lists.postgresql.org; Thu, 27 Apr 2023 14:46:35 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1ps2tE-005OaK-Kx for pgsql-bugs@lists.postgresql.org; Thu, 27 Apr 2023 14:46:35 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 33REkTkp1113610; Thu, 27 Apr 2023 10:46:29 -0400 From: Tom Lane To: Dmitry Dolgov <9erthalion6@gmail.com> cc: exclusion@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17908: plpython_to_hstore() crashes with a non-dict argument In-reply-to: <20230427082727.4na67kulnnlxkzq3@ddolgov.remote.csb> References: <17908-3f19a125d56a11d6@postgresql.org> <20230427082727.4na67kulnnlxkzq3@ddolgov.remote.csb> Comments: In-reply-to Dmitry Dolgov <9erthalion6@gmail.com> message dated "Thu, 27 Apr 2023 10:27:27 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1113608.1682606789.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 27 Apr 2023 10:46:29 -0400 Message-ID: <1113609.1682606789@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Dmitry Dolgov <9erthalion6@gmail.com> writes: >> On Tue, Apr 25, 2023 at 01:00:02PM +0000, PG Bug reporting form wrote: >> As noted in https://bugs.python.org/issue5945, the behaviour of >> PyMapping_Check() changed in Python 3, so it can't be used anymore to >> differentiate real dictionaries from strings or alike. > Thanks for finding this! That's indeed very annoying. Yuck. > After a quick > investigation looks like a proposed solution from [1] is to use > PyType_HasFeature with Py_TPFLAGS_MAPPING: > - if (!PyMapping_Check(dict)) > + dict_type =3D Py_TYPE(dict); > + if (!PyType_HasFeature(dict_type, Py_TPFLAGS_MAPPING)) > But this flag is available only starting from Python 3.10, so not > backward compatible :( Yeah, doesn't sound hugely workable; I don't think we can require 3.10 yet. The issue5945 discussion suggested >>> And recommend `PyMapping_Check() && !PySequence_Check()` for true mapp= ing test? I haven't verified this but will go test it shortly. If it's true, it would explain why our other uses of PyMapping_Check haven't failed, because (whether by chance or not I dunno) they are not reached if PySequence_Check is true. regards, tom lane