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 ddf97a0cdc
commit cdb206d3e7
2 changed files with 4 additions and 1 deletions

View File

@ -401,8 +401,10 @@ pq_complete_error(connectionObject *conn, PGresult **pgres, char **error)
* instead, and the connection gets closed in the pq_raise call above
* (see ticket #196)
*/
if (CONNECTION_BAD == PQstatus(conn->pgconn)) {
conn->closed = 2;
}
}
IFCLEARPGRES(*pgres);
if (*error) {
free(*error);

View File

@ -138,6 +138,7 @@ class LargeObjectTests(LargeObjectMixin, unittest.TestCase):
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()