mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-13 04:26:33 +03:00
Fixed dsn and closed attributes in failing connection subclasses.
From ticket #192 discussion. Conflicts: NEWS tests/test_connection.py
This commit is contained in:
parent
36a7deed52
commit
eddb0e3d90
2
NEWS
2
NEWS
|
@ -12,6 +12,8 @@ What's new in psycopg 2.4.7
|
|||
(:ticket:`#187`).
|
||||
- Avoid blocking async connections on connect (:ticket:`#194`). Thanks to
|
||||
Adam Petrovich for the bug report and diagnosis.
|
||||
- Fixed handling of dsn and closed attributes in connection subclasses
|
||||
failing to connect (from :ticket:`#192` discussion).
|
||||
- Don't segfault using poorly defined cursor subclasses which forgot to call
|
||||
the superclass init (:ticket:`#195`).
|
||||
- Fixed debug build on Windows, thanks to James Emerton.
|
||||
|
|
|
@ -629,14 +629,23 @@ _conn_async_connect(connectionObject *self)
|
|||
int
|
||||
conn_connect(connectionObject *self, long int async)
|
||||
{
|
||||
if (async == 1) {
|
||||
int rv;
|
||||
|
||||
if (async == 1) {
|
||||
Dprintf("con_connect: connecting in ASYNC mode");
|
||||
return _conn_async_connect(self);
|
||||
rv = _conn_async_connect(self);
|
||||
}
|
||||
else {
|
||||
Dprintf("con_connect: connecting in SYNC mode");
|
||||
return _conn_sync_connect(self);
|
||||
rv = _conn_sync_connect(self);
|
||||
}
|
||||
|
||||
if (rv != 0) {
|
||||
/* connection failed, so let's close ourselves */
|
||||
self->closed = 2;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1046,6 +1046,7 @@ connection_setup(connectionObject *self, const char *dsn, long int async)
|
|||
res = 0;
|
||||
}
|
||||
|
||||
exit:
|
||||
/* here we obfuscate the password even if there was a connection error */
|
||||
pos = strstr(self->dsn, "password");
|
||||
if (pos != NULL) {
|
||||
|
@ -1053,7 +1054,6 @@ connection_setup(connectionObject *self, const char *dsn, long int async)
|
|||
*pos = 'x';
|
||||
}
|
||||
|
||||
exit:
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -218,6 +218,18 @@ class ConnectionTests(unittest.TestCase):
|
|||
|
||||
self.assert_(not notices, "%d notices raised" % len(notices))
|
||||
|
||||
def test_failed_init_status(self):
|
||||
class SubConnection(psycopg2.extensions.connection):
|
||||
def __init__(self, dsn):
|
||||
try:
|
||||
super(SubConnection, self).__init__(dsn)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
c = SubConnection("dbname=thereisnosuchdatabasemate password=foobar")
|
||||
self.assert_(c.closed, "connection failed so it must be closed")
|
||||
self.assert_('foobar' not in c.dsn, "password was not obscured")
|
||||
pass
|
||||
|
||||
class IsolationLevelsTestCase(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user