Check the connection is really bad on exception before closing it

We end up here without a pgres sometimes (e.g. from lobject errors)
This commit is contained in:
Daniele Varrazzo 2014-04-05 15:14:00 +01:00
parent f0c38f0b37
commit e5ab0b3987
2 changed files with 4 additions and 1 deletions

View File

@ -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 * instead, and the connection gets closed in the pq_raise call above
* (see ticket #196) * (see ticket #196)
*/ */
conn->closed = 2; if (CONNECTION_BAD == PQstatus(conn->pgconn)) {
conn->closed = 2;
}
} }
if (*error) { if (*error) {

View File

@ -130,6 +130,7 @@ class LargeObjectTests(LargeObjectTestCase):
self.assertRaises(psycopg2.OperationalError, self.assertRaises(psycopg2.OperationalError,
self.conn.lobject, 0, "w", lo.oid) self.conn.lobject, 0, "w", lo.oid)
self.assert_(not self.conn.closed)
def test_import(self): def test_import(self):
self.tmpdir = tempfile.mkdtemp() self.tmpdir = tempfile.mkdtemp()