Re: Weird PL/Python elog output

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Marko Kreen <markokr(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Weird PL/Python elog output
Date: 2009-10-31 10:13:53
Message-ID: 1256984033.28195.2.camel@vanquo.pezone.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On fre, 2009-10-30 at 17:13 +0200, Marko Kreen wrote:
> On 10/30/09, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> > Calling PL/Python's elog functions exposes some curious behavior. For
> > example, calling plpy.error('foo') prints
> >
> > ERROR: ('foo',)
> >
> > (instead of the
> >
> > ERROR: foo
> >
> > that one might have hoped for.) This is an implementation artifact,
> > because those functions don't check their arguments, just take them as a
> > tuple, convert the tuple to a string, and a singleton tuples look like
> > the above as a string.

> I vote for handling tuple with 1 element better, otherwise keep old
> behaviour.
>
> I don't think breaking multi-arg calls is good idea, as they may be used
> only in special situations. OTOH, it does not seem worthwhile to
> spend effort trying to handle them better.

OK, how about this:

diff --git a/src/pl/plpython/plpython.c b/src/pl/plpython/plpython.c
index 313b760..783f625 100644
--- a/src/pl/plpython/plpython.c
+++ b/src/pl/plpython/plpython.c
@@ -3080,6 +3080,13 @@ PLy_output(volatile int level, PyObject *self,
PyObject *args)
char *volatile sv;
MemoryContext oldcontext;

+ if (PyTuple_Size(args) == 1)
+ {
+ PyObject *o;
+ PyArg_UnpackTuple(args, "plpy.elog", 1, 1, &o);
+ so = PyObject_Str(o);
+ }
+ else
so = PyObject_Str(args);
if (so == NULL || ((sv = PyString_AsString(so)) == NULL))
{

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Magnus Hagander 2009-10-31 10:20:45 Re: [HACKERS] FTP/GIT/WWW server move
Previous Message Peter Eisentraut 2009-10-31 08:54:01 Re: [HACKERS] FTP/GIT/WWW server move