Re: pl/python tracebacks v2

Lists: pgsql-hackers
From: Jan Urbański <wulczer(at)wulczer(dot)org>
To: Postgres - Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: pl/python tracebacks v2
Date: 2011-03-20 23:40:02
Message-ID: 4D869052.4020602@wulczer.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I finally got around to updating the PL/Python tracebacks patch. The
other day I was writing some very simple PL/Python code and the lack of
tracebacks is extremely annoying.

Getting a TypeError without any line information in a function with 30
lines because there's a %d instead of a %s somewhere in a logging call
can make your debugging experience very lousy.

Attached is a patch against master, with simplified error forming logic
and the traceback in the context field. If you look at the expected
regression test output, you will see that the only thing that changes is
the presense of tracebacks in context messages.

I'll update the commitfest app for the 2011-Next commitfest, but if
someone would like to pick this up and include it in the 9.1 PL/Python
revamp pack, I'd be thrilled.

Cheers,
Jan

Attachment Content-Type Size
plpython-tracebacks-v2.diff text/x-patch 60.0 KB

From: Peter Geoghegan <peter(at)2ndquadrant(dot)com>
To: Jan Urbański <wulczer(at)wulczer(dot)org>
Cc: Postgres - Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pl/python tracebacks v2
Date: 2011-03-21 01:47:18
Message-ID: AANLkTi=TKRe8ps1EYEvAFpachQkUyExE6U+VOxiQio3w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 20 March 2011 23:40, Jan Urbański <wulczer(at)wulczer(dot)org> wrote:
> I'll update the commitfest app for the 2011-Next commitfest, but if
> someone would like to pick this up and include it in the 9.1 PL/Python
> revamp pack, I'd be thrilled.

I would also be thrilled. I definitely share your sense of frustration
about the lack of tracebacks available when writing pl/python.

--
Peter Geoghegan       http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training and Services


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: pl/python tracebacks v2
Date: 2011-04-06 19:38:25
Message-ID: 1302118705.14384.5.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On mån, 2011-03-21 at 00:40 +0100, Jan Urbański wrote:
> I finally got around to updating the PL/Python tracebacks patch. The
> other day I was writing some very simple PL/Python code and the lack of
> tracebacks is extremely annoying.

I tweaked this a bit to make the patch less invasive, and then committed
it. :)


From: Jan Urbański <wulczer(at)wulczer(dot)org>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Postgres - Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pl/python tracebacks v2
Date: 2011-04-06 20:16:13
Message-ID: 4D9CCA0D.5070400@wulczer.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 06/04/11 21:38, Peter Eisentraut wrote:
> On mån, 2011-03-21 at 00:40 +0100, Jan Urbański wrote:
>> I finally got around to updating the PL/Python tracebacks patch. The
>> other day I was writing some very simple PL/Python code and the lack of
>> tracebacks is extremely annoying.
>
> I tweaked this a bit to make the patch less invasive, and then committed
> it. :)

Ouch, just today I found a flaw in this, namely that it assumes the
lineno from the traceback always refers to the PL/Python function. If
you create a PL/Python function that imports some code, runs it, and
that code raises an exception, PLy_traceback will get utterly confused.

Working on a fix...

Jan

PS: obviously it'd be great to have PL/Python traceback support in 9.1,
but I sure hope we'll get some testing in beta for issues like this...

J


From: Jan Urbański <wulczer(at)wulczer(dot)org>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Postgres - Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pl/python tracebacks v2
Date: 2011-04-06 21:54:41
Message-ID: 4D9CE121.1000606@wulczer.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 06/04/11 22:16, Jan Urbański wrote:
> On 06/04/11 21:38, Peter Eisentraut wrote:
>> On mån, 2011-03-21 at 00:40 +0100, Jan Urbański wrote:
>>> I finally got around to updating the PL/Python tracebacks patch. The
>>> other day I was writing some very simple PL/Python code and the lack of
>>> tracebacks is extremely annoying.
>>
>> I tweaked this a bit to make the patch less invasive, and then committed
>> it. :)
>
> Ouch, just today I found a flaw in this, namely that it assumes the
> lineno from the traceback always refers to the PL/Python function. If
> you create a PL/Python function that imports some code, runs it, and
> that code raises an exception, PLy_traceback will get utterly confused.
>
> Working on a fix...

Here's the fix.

The actual bug was funny. The traceback code was fetching the file line
from the traceback and trying to get that line from the original source
to print it. But sometimes that line was refering to a different source
file, like when the exception originated from an imported module.

In my testing I accidentally had the error (in a separate module) on
line 2, so the traceback code tried to fetch line 2 of the function,
which was completely whitespace. This can never happen in theory,
because you can't have a frame starting at an all-whitespace line. The
code to get that line was misbehaving and trying to do a malloc(-2),
which in turn was causing an "ERROR invalid memory allocation".

All that is fixed with the attached patch.

Cheers,
Jan

PS: and thanks for committing that in the first place! :)

J

Attachment Content-Type Size
plpython-traceback-bug.patch text/x-patch 3.7 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: pl/python tracebacks v2
Date: 2011-04-20 20:22:33
Message-ID: 1303330953.24785.15.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wed, 2011-04-06 at 23:54 +0200, Jan Urbański wrote:
> > Ouch, just today I found a flaw in this, namely that it assumes the
> > lineno from the traceback always refers to the PL/Python function. If
> > you create a PL/Python function that imports some code, runs it, and
> > that code raises an exception, PLy_traceback will get utterly confused.
> >
> > Working on a fix...
>
> Here's the fix.

Committed.