From d71520db9a7fdd4739677ad066fd8a3d9b118d75 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Wed, 21 Apr 2010 13:22:09 +0100 Subject: [PATCH] Read the server version only after connection established. --- psycopg/connection_int.c | 4 ++-- tests/test_connection.py | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/psycopg/connection_int.c b/psycopg/connection_int.c index dd805767..e564cfc7 100644 --- a/psycopg/connection_int.c +++ b/psycopg/connection_int.c @@ -374,8 +374,6 @@ conn_sync_connect(connectionObject *self) Dprintf("conn_connect: using protocol %d", self->protocol); - self->server_version = (int)PQserverVersion(pgconn); - /* if the connection is green, wait to finish connection */ if (green) { wait_rv = psyco_wait(self); @@ -386,6 +384,8 @@ conn_sync_connect(connectionObject *self) } } + self->server_version = (int)PQserverVersion(pgconn); + /* From here the connection is considered ready: with the new status, * poll() will use PQisBusy instead of PQconnectPoll. */ diff --git a/tests/test_connection.py b/tests/test_connection.py index 277616b4..dbb80afa 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -45,8 +45,12 @@ class ConnectionTests(unittest.TestCase): self.assert_(conn.notices) conn.close() + def test_server_version(self): + conn = self.connect() + self.assert_(conn.server_version) + def test_suite(): return unittest.TestLoader().loadTestsFromName(__name__) if __name__ == "__main__": - unittest.main() \ No newline at end of file + unittest.main()