Problem with error handling

From: "Eric Snow" <esnow(at)verio(dot)net>
To: <psycopg(at)postgresql(dot)org>
Subject: Problem with error handling
Date: 2011-04-23 01:56:13
Message-ID: D2F744D05ED19D45A4A7757F49274A8B042F126E@IAD-WPRD-XCHB01.corp.verio.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

I'm getting a "SystemError: null argument to internal routine" problem
that is gobbling up the actual error. I turned on debugging and see
that the problem is that my connection is closed (and I have to connect
a second time to get it to work). However, the SystemError hid this
until I turned on debugging.

In trying to find why the SystemError is happening, I found that at the
point pq_raise is called, no exception has been set. The conn and pgres
objects are fine and the cursor is NULL. The following call is NULL:

code = PQresultErrorField(pgres, PG_DIAG_SQLSTATE);

This results in "exc" staying null. Thus, when psyco_set_error is
called, only msg and pgerror are not NULL. Since the cursor is NULL,
the connection object is not pulled, and the following line is valid:

pymsg = conn_text_from_chars(conn, msg)

Subsequently, the following is called with "exc" set to NULL:

err = PyObject_CallFunctionObjArgs(exc, pymsg, NULL);

Thus err is NULL and the if statement is not called. Because it is not
called, PyErr_SetObject is never called. All of this started with a
call to cursor.execute in Python. That dropped down into the C module's
psyco_curs_execute. That returns NULL without the PyErr object set,
which results in the SystemError.

I am guessing that the solution is one of the following:

* PQresultErrorField should not have returned NULL
* "exc" should have been calculated another way (like an else after the
"if (code != NULL)")

Regardless of the solution, thanks for your time.

-eric

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

Responses

Browse psycopg by date

  From Date Subject
Next Message Daniele Varrazzo 2011-04-24 01:47:55 Re: Problem with error handling
Previous Message Daniele Varrazzo 2011-04-18 16:39:28 Re: client encoding name normalization in psycopg 2.4