Skip to content

Commit 25e21b2

Browse files
committed
Reveal the appropriate exception during dbapi20.connect(); db.close chained ClientCannotConnect.
1 parent 176b0c7 commit 25e21b2

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

postgresql/driver/dbapi20.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ class Connection(Connection):
323323
Warning
324324
DatabaseError = DatabaseError
325325
NotSupportedError = NotSupportedError
326+
_dbapi_connected = False
326327

327328
def autocommit_set(self, val):
328329
if val:
@@ -354,9 +355,10 @@ def connect(self, *args, **kw):
354355
super().connect(*args, **kw)
355356
self._xact = self.xact()
356357
self._xact.start()
358+
self._dbapi_connected = True
357359

358360
def close(self):
359-
if self.closed:
361+
if self.closed and self._dbapi_connected:
360362
raise Error(
361363
"connection already closed",
362364
source = 'CLIENT',

0 commit comments

Comments
 (0)