You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IlyaFaer opened this issue
Aug 20, 2020
· 0 comments
· Fixed by #463
Assignees
Labels
api: spannerIssues 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 to True:
Raise an exception if attempting to use an already closed connection.
"""
ifself._closed:
raiseInterfaceError('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:
ifself._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.
The text was updated successfully, but these errors were encountered:
api: spannerIssues 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: