-
Notifications
You must be signed in to change notification settings - Fork 31
Description
According to PEP-249, on connection closing all the related cursors must become no-op as well. The current implementation of closes and checks has an issue at this point.
Connection.close()
only sets the connection attribute to True
:
python-spanner-django/spanner_dbapi/connection.py
Lines 112 to 115 in 11222db
def close(self): | |
self.rollback() | |
self.__dbhandle = None | |
self._closed = True |
While the Cursor
checking method is only looking for the Cursor._closed
attribute:
python-spanner-django/spanner_dbapi/cursor.py
Lines 219 to 224 in 11222db
def _raise_if_already_closed(self): | |
""" | |
Raise an exception if attempting to use an already closed connection. | |
""" | |
if self._closed: | |
raise InterfaceError('cursor already closed') |
That means cursor don't know if the related connection is already closed. Technically, it doesn't look like a big problem, as Cursor.execute()
delegates to Connection
, and the connection will raise an exception already closed
. But there are several commands, which will be runned on a closed Cursor
before the exception raised, for example, classify_stmt(sql)
.
To avoid that it'll be good to add into Cursor._raise_if_already_closed()
a line like:
if self._connection.is_closed:
raise ...
Checking a bool is much more faster than regexping SQL code and passing it into a connection method.
Plus to this, I'd make is_closed
attribute public, so that users could check if a cursor/connection is closed.