Skip to content

Commit e1a2c0e

Browse files
fix: separate session opening logic from instantiation
ensures correctness of self.session.open call in Connection Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent a61df99 commit e1a2c0e

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/databricks/sql/client.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ def read(self) -> Optional[OAuthToken]:
243243
_use_arrow_native_complex_types,
244244
**kwargs,
245245
)
246+
self.session.open()
246247

247248
logger.info(
248249
"Successfully opened connection with session "
@@ -343,9 +344,7 @@ def get_protocol_version(openSessionResp):
343344
@property
344345
def open(self) -> bool:
345346
"""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
347+
return self.session.is_open
349348

350349
def cursor(
351350
self,

src/databricks/sql/session.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ def __init__(
3131
3232
This class handles all session-related behavior and communication with the backend.
3333
"""
34-
self.open = False
34+
self.is_open = False
3535
self.host = server_hostname
3636
self.port = kwargs.get("_port", 443)
3737

38+
self.session_configuration = session_configuration
39+
self.catalog = catalog
40+
self.schema = schema
41+
3842
auth_provider = get_python_sql_connector_auth_provider(
3943
server_hostname, **kwargs
4044
)
@@ -151,4 +155,4 @@ def close(self) -> None:
151155
except Exception as e:
152156
logger.error(f"Attempt to close session raised a local exception: {e}")
153157

154-
self.open = False
158+
self.is_open = False

0 commit comments

Comments
 (0)