Skip to content

Commit 3f7bc2c

Browse files
committed
Hold the DB-API 2.0 exception change until 1.3 for fear of breaking offline dependencies and add a test checking for desired behaviour.
1 parent 957f829 commit 3f7bc2c

4 files changed

Lines changed: 17 additions & 3 deletions

File tree

README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Errata
1515
------
1616

1717
.. warning::
18-
`postgresql.driver.dbapi20.connect` will now raise `ClientCannotConnectError` directly.
18+
In v1.3, `postgresql.driver.dbapi20.connect` will now raise `ClientCannotConnectError` directly.
1919
Exception traps around connect should still function, but the `__context__` attribute
2020
on the error instance will be `None` in the usual failure case as it is no longer
2121
incorrectly chained. Trapping `ClientCannotConnectError` ahead of `Error` should

postgresql/driver/dbapi20.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,9 @@ class Connection(Connection):
323323
Warning
324324
DatabaseError = DatabaseError
325325
NotSupportedError = NotSupportedError
326+
327+
# Explicitly manage DB-API connected state to properly
328+
# throw the already closed error. This will be active in 1.3.
326329
_dbapi_connected_flag = False
327330

328331
def autocommit_set(self, val):
@@ -358,7 +361,7 @@ def connect(self, *args, **kw):
358361
self._dbapi_connected_flag = True
359362

360363
def close(self):
361-
if self.closed and self._dbapi_connected_flag:
364+
if self.closed:# and self._dbapi_connected_flag:
362365
raise Error(
363366
"connection already closed",
364367
source = 'CLIENT',

postgresql/release/distutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
LONG_DESCRIPTION = """
2222
.. warning::
23-
`postgresql.driver.dbapi20.connect` will now raise `ClientCannotConnectError` directly.
23+
In v1.3, `postgresql.driver.dbapi20.connect` will now raise `ClientCannotConnectError` directly.
2424
Exception traps around connect should still function, but the `__context__` attribute
2525
on the error instance will be `None` in the usual failure case as it is no longer
2626
incorrectly chained. Trapping `ClientCannotConnectError` ahead of `Error` should

postgresql/test/test_connect.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,17 @@ def test_dbapi_connect(self):
410410
TRUST.cursor().execute, 'select 1'
411411
)
412412

413+
def test_dbapi_connect_failure(self):
414+
host, port = self.cluster.address()
415+
badlogin = (lambda: dbapi20.connect(
416+
user = '--',
417+
database = '--',
418+
password = '...',
419+
host = host, port = port,
420+
**self.params
421+
))
422+
self.assertRaises(pg_exc.ClientCannotConnectError, badlogin)
423+
413424
def test_IP4_connect(self):
414425
C = pg_driver.default.ip4(
415426
user = 'test',

0 commit comments

Comments
 (0)