Connection.close() doesn't close cursors #461
Labels
api: spanner
Issues related to the googleapis/python-spanner-django API.
type: feature request
‘Nice-to-have’ improvement, new feature or different behavior or design.
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 toTrue
:python-spanner-django/spanner_dbapi/connection.py
Lines 112 to 115 in 11222db
While the
Cursor
checking method is only looking for theCursor._closed
attribute:python-spanner-django/spanner_dbapi/cursor.py
Lines 219 to 224 in 11222db
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 toConnection
, and the connection will raise an exceptionalready closed
. But there are several commands, which will be runned on a closedCursor
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: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.The text was updated successfully, but these errors were encountered: