Skip to content

Commit 3fd2a46

Browse files
decouple session class from existing Connection
ensure maintenance of current APIs of Connection while delegating responsibility Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent 0917ea1 commit 3fd2a46

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/databricks/sql/client.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
OperationalError,
2020
SessionAlreadyClosedError,
2121
CursorAlreadyClosedError,
22+
Error,
23+
NotSupportedError,
2224
)
2325
from databricks.sql.thrift_api.TCLIService import ttypes
2426
from databricks.sql.backend.thrift_backend import ThriftDatabricksClient
@@ -306,7 +308,7 @@ def __exit__(self, exc_type, exc_value, traceback):
306308
return False
307309

308310
def __del__(self):
309-
if self.open:
311+
if self.session.open:
310312
logger.debug(
311313
"Closing unclosed connection for session "
312314
"{}".format(self.get_session_id_hex())
@@ -340,13 +342,6 @@ def get_protocol_version(openSessionResp):
340342
"""Delegate to Session class static method"""
341343
return Session.get_protocol_version(openSessionResp)
342344

343-
@property
344-
def open(self) -> bool:
345-
"""Return whether the connection is open by checking if the session is open."""
346-
# NOTE: we have to check for the existence of session in case the __del__ is called
347-
# before the session is instantiated
348-
return hasattr(self, "session") and self.session.open
349-
350345
def cursor(
351346
self,
352347
arraysize: int = DEFAULT_ARRAY_SIZE,
@@ -357,7 +352,7 @@ def cursor(
357352
358353
Will throw an Error if the connection has been closed.
359354
"""
360-
if not self.open:
355+
if not self.session.open:
361356
raise Error("Cannot create cursor from closed connection")
362357

363358
cursor = Cursor(

0 commit comments

Comments
 (0)