From e5ab0b39875b0cfd6e1cea77b3122e3f18ff520e Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sat, 5 Apr 2014 15:14:00 +0100 Subject: [PATCH] Check the connection is really bad on exception before closing it We end up here without a pgres sometimes (e.g. from lobject errors) --- psycopg/pqpath.c | 4 +++- tests/test_lobject.py | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/psycopg/pqpath.c b/psycopg/pqpath.c index 1a701524..d33915c8 100644 --- a/psycopg/pqpath.c +++ b/psycopg/pqpath.c @@ -428,7 +428,9 @@ pq_complete_error(connectionObject *conn, PGresult **pgres, char **error) * instead, and the connection gets closed in the pq_raise call above * (see ticket #196) */ - conn->closed = 2; + if (CONNECTION_BAD == PQstatus(conn->pgconn)) { + conn->closed = 2; + } } if (*error) { diff --git a/tests/test_lobject.py b/tests/test_lobject.py index e62e0d85..a7781e68 100755 --- a/tests/test_lobject.py +++ b/tests/test_lobject.py @@ -130,6 +130,7 @@ class LargeObjectTests(LargeObjectTestCase): self.assertRaises(psycopg2.OperationalError, self.conn.lobject, 0, "w", lo.oid) + self.assert_(not self.conn.closed) def test_import(self): self.tmpdir = tempfile.mkdtemp()