Re: exceptions not present in plpy with Python 3

Lists: pgsql-hackers
From: Jan Urbański <wulczer(at)wulczer(dot)org>
To: Postgres - Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: exceptions not present in plpy with Python 3
Date: 2010-12-18 17:56:29
Message-ID: 4D0CF5CD.4040301@wulczer.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

there seems to be a problem in the way we add exceptions to the plpy
module in PL/Python compiled with Python 3k.

Try this: DO $$ plpy.SPIError $$ language plpython3u;

I'm not a Python 3 expert, but I nicked some code from the Internet and
came up with this patch (passes regression tests on both Python 2 and 3).

The funny thing is that it never blew up earlier, because we only used
plpy.SPIError in except: blocks that weren't even executed, as errors in
plpy.execute just terminate the function.

With my changes they turn into catchable exceptions, and so accessing
plpy.SPIError in Python 3 becomes essential.

BTW: do we have any buildfarm animal that uses Python 3?

Cheers,
Jan

Attachment Content-Type Size
plpython3-exceptions.diff text/x-patch 4.2 KB

From: Jan Urbański <wulczer(at)wulczer(dot)org>
To: Postgres - Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: exceptions not present in plpy with Python 3
Date: 2010-12-18 18:33:00
Message-ID: 4D0CFE5C.5060704@wulczer.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 18/12/10 18:56, Jan Urbański wrote:
> I'm not a Python 3 expert, but I nicked some code from the Internet and
> came up with this patch (passes regression tests on both Python 2 and 3).

I tried to be too cute with the regression test, it fails with Python
2.3.7 (the latest 2.3 release).

Attached is a fixed test that should work in Pythons 2.3+

I don't want to open that can of worms just yet, but do we have any
formal policy on the oldest Python version we support? I tested on 2.3
just because looking at http://python.org/download/releases/ I saw that
2.2 was last released in 2003, so I thought 2.3 was as far as I'd go...

Cheers,
Jan

Attachment Content-Type Size
plpython3-exceptions-v2.diff text/x-patch 4.2 KB

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Jan Urbański <wulczer(at)wulczer(dot)org>
Cc: Postgres - Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: exceptions not present in plpy with Python 3
Date: 2011-01-20 20:30:04
Message-ID: 1295555404.27153.1.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On lör, 2010-12-18 at 18:56 +0100, Jan Urbański wrote:
> there seems to be a problem in the way we add exceptions to the plpy
> module in PL/Python compiled with Python 3k.
>
> Try this: DO $$ plpy.SPIError $$ language plpython3u;
>
> I'm not a Python 3 expert, but I nicked some code from the Internet and
> came up with this patch (passes regression tests on both Python 2 and 3).

It looks like the PyModule_AddObject() approach also works in Python 2.
Anyone see an issue with using that uniformly?


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Jan Urbański <wulczer(at)wulczer(dot)org>
Cc: Postgres - Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: exceptions not present in plpy with Python 3
Date: 2011-01-21 21:49:37
Message-ID: 1295646577.8026.0.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On tor, 2011-01-20 at 22:30 +0200, Peter Eisentraut wrote:
> On lör, 2010-12-18 at 18:56 +0100, Jan Urbański wrote:
> > there seems to be a problem in the way we add exceptions to the plpy
> > module in PL/Python compiled with Python 3k.
> >
> > Try this: DO $$ plpy.SPIError $$ language plpython3u;
> >
> > I'm not a Python 3 expert, but I nicked some code from the Internet and
> > came up with this patch (passes regression tests on both Python 2 and 3).
>
> It looks like the PyModule_AddObject() approach also works in Python 2.
> Anyone see an issue with using that uniformly?

Committed using PyModule_AddObject.