Re: BUG #17908: plpython_to_hstore() crashes with a non-dict argument - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #17908: plpython_to_hstore() crashes with a non-dict argument
Date
Msg-id 1113609.1682606789@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #17908: plpython_to_hstore() crashes with a non-dict argument  (Dmitry Dolgov <9erthalion6@gmail.com>)
List pgsql-bugs
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 = 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 mapping 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



pgsql-bugs by date:

Previous
From: Daniel Gustafsson
Date:
Subject: Re: pg_basebackup: errors on macOS on directories with ".DS_Store" files
Next
From: PG Bug reporting form
Date:
Subject: BUG #17911: Database or JDBC Driver Provides Incorrect Type