Skip to content

Commit c676f9b

Browse files
fix: ensure open attribute of Connection never fails
in case the openSession takes long, the initialisation of the session will not complete immediately. This could make the session attribute inaccessible. If the Connection is deleted in this time, the open() check will throw because the session attribute does not exist. Thus, we default to the Connection being closed in this case. This was not an issue before because open was a direct attribute of the Connection class. Caught in the integration tests. Signed-off-by: varun-edachali-dbx <[email protected]>
1 parent 078f91a commit c676f9b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/databricks/sql/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
OperationalError,
2020
SessionAlreadyClosedError,
2121
CursorAlreadyClosedError,
22-
Error,
23-
NotSupportedError,
2422
)
2523
from databricks.sql.thrift_api.TCLIService import ttypes
2624
from databricks.sql.thrift_backend import ThriftBackend
@@ -319,7 +317,9 @@ def get_protocol_version(openSessionResp):
319317
@property
320318
def open(self) -> bool:
321319
"""Return whether the connection is open by checking if the session is open."""
322-
return self.session.open
320+
# NOTE: we have to check for the existence of session in case the __del__ is called
321+
# before the session is instantiated
322+
return hasattr(self, "session") and self.session.open
323323

324324
def cursor(
325325
self,

0 commit comments

Comments
 (0)