Re: SystemError: null argument to internal routine - Mailing list psycopg

From Eric Snow
Subject Re: SystemError: null argument to internal routine
Date
Msg-id D2F744D05ED19D45A4A7757F49274A8B0416F8DA@IAD-WPRD-XCHB01.corp.verio.net
Whole thread Raw
In response to Re: SystemError: null argument to internal routine  (Jan Urbański <wulczer@wulczer.org>)
Responses Re: SystemError: null argument to internal routine  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
List psycopg
Thanks Jan, that helps explain that.  So you are saying that the problem is in pq_raise at the end of the function.  If
"code"is NULL then "exc" is still NULL, which results in the SystemError.  While the handling of the empty query is one
thing,the handling of errors where "code" is NULL is another.  Seems like two separate issue that should both be
addressed. Should there be separate tickets for this, or is the ticket Daniele made sufficient?  Thanks. 

-eric

-----Original Message-----
From: Jan Urbański [mailto:wulczer@wulczer.org]
Sent: Thursday, March 03, 2011 1:02 PM
To: Eric Snow
Cc: psycopg@postgresql.org
Subject: Re: [psycopg] SystemError: null argument to internal routine

On 03/03/11 20:52, Eric Snow wrote:
> I am trying to figure out the conditions under which I get that
> SystemError.  Here is a simple way that I found to reproduce the
> problem:
>
>>>> import psycopg2
>>>> psycopg2.__version__
> '2.3.2 (dt dec pq3 ext)'
>>>> conn = psycopg2.connect("...")
>>>> cur = conn.cursor()
>>>> cur.execute(";")
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> SystemError: null argument to internal routine
>
> I am getting the same exception during a call to copy_expert.  How would
> the data I pass in there trigger the same exception as when I pass a
> single semicolon?  I am guessing that it does not even make it over the
> wire to the postgres server when the exception is raised.  Thanks.

Aaah, that rings a bell. I was getting the same error with txpostgres
and even once found out why, but forgot, and now I remembered.

I believe that the problem is in pqpath.c, in pq_fetch. There's a switch
statement there that checks the result of PQresultStatus and does not
take PGRES_EMPTY_QUERY into consideration.

The code that jumps to the default: label, which leads it to pq_raise.
Towards the end there's a

if (code != NULL)
   exc = exception_from_sqlstate(code);

which AFAIR never gets executed, because code *is* NULL. And then it
hits psyco_set_error with a NULL exception, this leads to the "NULL
argument to internal routine" error.

I might have messed up some details, but I'm pretty sure the problem is
not handling PGRES_EMPTY_QUERY correctly.

Cheers,
Jan


This email message is intended for the use of the person to whom it has been sent, and may contain information that is
confidentialor legally protected. If you are not the intended recipient or have received this message in error, you are
notauthorized to copy, distribute, or otherwise use this message or its attachments. Please notify the sender
immediatelyby return e-mail and permanently delete this message and any attachments. Verio, Inc. makes no warranty that
thisemail is error or virus free.  Thank you. 

psycopg by date:

Previous
From: Daniele Varrazzo
Date:
Subject: Re: SystemError: null argument to internal routine
Next
From: Daniele Varrazzo
Date:
Subject: Re: SystemError: null argument to internal routine