mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-23 01:16:34 +03:00
Meaningful connection errors report a meaningful message
Fixes issue #173.
This commit is contained in:
parent
0e08fbb20b
commit
09cf64dda4
2
NEWS
2
NEWS
|
@ -6,6 +6,8 @@ What's new in psycopg 2.5.2
|
|||
|
||||
- Fixed segfault pickling the exception raised on connection error
|
||||
(:ticket:`#170`).
|
||||
- Meaningful connection errors report a meaningful message, thanks to
|
||||
Alexey Borzenkov (:ticket:`#173`).
|
||||
|
||||
|
||||
What's new in psycopg 2.5.1
|
||||
|
|
|
@ -642,6 +642,7 @@ static int
|
|||
_conn_poll_connecting(connectionObject *self)
|
||||
{
|
||||
int res = PSYCO_POLL_ERROR;
|
||||
const char *msg;
|
||||
|
||||
Dprintf("conn_poll: poll connecting");
|
||||
switch (PQconnectPoll(self->pgconn)) {
|
||||
|
@ -656,7 +657,11 @@ _conn_poll_connecting(connectionObject *self)
|
|||
break;
|
||||
case PGRES_POLLING_FAILED:
|
||||
case PGRES_POLLING_ACTIVE:
|
||||
PyErr_SetString(OperationalError, "asynchronous connection failed");
|
||||
msg = PQerrorMessage(self->pgconn);
|
||||
if (!(msg && *msg)) {
|
||||
msg = "asynchronous connection failed";
|
||||
}
|
||||
PyErr_SetString(OperationalError, msg);
|
||||
res = PSYCO_POLL_ERROR;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -449,6 +449,16 @@ class AsyncTests(ConnectingTestCase):
|
|||
self.wait(self.conn)
|
||||
self.assertEqual(cur.fetchone(), (42,))
|
||||
|
||||
def test_async_connection_error_message(self):
|
||||
try:
|
||||
cnn = psycopg2.connect('dbname=thisdatabasedoesntexist', async=True)
|
||||
self.wait(cnn)
|
||||
except psycopg2.Error, e:
|
||||
self.assertNotEqual(str(e), "asynchronous connection failed",
|
||||
"connection error reason lost")
|
||||
else:
|
||||
self.fail("no exception raised")
|
||||
|
||||
|
||||
def test_suite():
|
||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
|
Loading…
Reference in New Issue
Block a user