From c08799b0b03b65d3a03f1bee86fc51bc682a4549 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sun, 24 Apr 2011 02:57:04 +0100 Subject: [PATCH] Fixed SystemError clobbering libpq errors raised without SQLSTATE Bug vivisectioned by Eric Snow . --- NEWS | 2 ++ psycopg/pqpath.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/NEWS b/NEWS index 6f8e48a4..60c7d4b3 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,8 @@ What's new in psycopg 2.4.1 - Don't fail connection if the client encoding is a non-normalized variant. Issue reported by Peter Eisentraut. - Correctly detect an empty query sent to the backend (ticket #46). + - Fixed a SystemError clobbering libpq errors raised without SQLSTATE. + Bug vivisectioned by Eric Snow. - Allow to specify --static-libpq on setup.py command line instead of just in 'setup.cfg'. Patch provided by Matthew Ryan (ticket #48). diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c index 8d144dce..6a6d05a3 100644 --- a/psycopg/pqpath.c +++ b/psycopg/pqpath.c @@ -194,6 +194,11 @@ pq_raise(connectionObject *conn, cursorObject *curs, PGresult *pgres) if (code != NULL) { exc = exception_from_sqlstate(code); } + else { + /* Fallback if there is no exception code (reported happening e.g. + * when the connection is closed). */ + exc = DatabaseError; + } /* try to remove the initial "ERROR: " part from the postgresql error */ err2 = strip_severity(err);