Skip to content

Commit db2f0c1

Browse files
committed
Turn the connected flag on if the close passes so that subsequent closes will raise the desired exception.
1 parent 05ee2b0 commit db2f0c1

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

postgresql/driver/dbapi20.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ class Connection(Connection):
323323
Warning
324324
DatabaseError = DatabaseError
325325
NotSupportedError = NotSupportedError
326-
_dbapi_connected = False
326+
_dbapi_connected_flag = False
327327

328328
def autocommit_set(self, val):
329329
if val:
@@ -355,15 +355,16 @@ def connect(self, *args, **kw):
355355
super().connect(*args, **kw)
356356
self._xact = self.xact()
357357
self._xact.start()
358-
self._dbapi_connected = True
358+
self._dbapi_connected_flag = True
359359

360360
def close(self):
361-
if self.closed and self._dbapi_connected:
361+
if self.closed and self._dbapi_connected_flag:
362362
raise Error(
363363
"connection already closed",
364364
source = 'CLIENT',
365365
creator = self
366366
)
367+
self._dbapi_connected_flag = True
367368
super().close()
368369

369370
def cursor(self):

0 commit comments

Comments
 (0)