Skip to content

Commit 0df486a

Browse files
fix: de-complicate earlier connection open logic
earlier, one of the integration tests was failing because 'session was not an attribute of Connection'. This is likely tied to a local configuration issue related to unittest that was causing an error in the test suite itself. The tests are now passing without checking for the session attribute. databricks@c676f9b Signed-off-by: varun-edachali-dbx <[email protected]>
1 parent ff35165 commit 0df486a

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/databricks/sql/client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,7 @@ def get_protocol_version(openSessionResp):
317317
@property
318318
def open(self) -> bool:
319319
"""Return whether the connection is open by checking if the session is 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
320+
return self.session.is_open
323321

324322
def cursor(
325323
self,

src/databricks/sql/session.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(
2929
3030
This class handles all session-related behavior and communication with the backend.
3131
"""
32-
self.open = False
32+
self.is_open = False
3333
self.host = server_hostname
3434
self.port = kwargs.get("_port", 443)
3535

@@ -77,13 +77,12 @@ def __init__(
7777
_use_arrow_native_complex_types=_use_arrow_native_complex_types,
7878
**kwargs,
7979
)
80-
8180
self._open_session_resp = self.thrift_backend.open_session(
8281
session_configuration, catalog, schema
8382
)
8483
self._session_handle = self._open_session_resp.sessionHandle
8584
self.protocol_version = self.get_protocol_version(self._open_session_resp)
86-
self.open = True
85+
self.is_open = True
8786
logger.info("Successfully opened session " + str(self.get_session_id_hex()))
8887

8988
@staticmethod
@@ -122,7 +121,7 @@ def get_session_id_hex(self):
122121
def close(self) -> None:
123122
"""Close the underlying session."""
124123
logger.info(f"Closing session {self.get_session_id_hex()}")
125-
if not self.open:
124+
if not self.is_open:
126125
logger.debug("Session appears to have been closed already")
127126
return
128127

@@ -143,4 +142,4 @@ def close(self) -> None:
143142
except Exception as e:
144143
logger.error(f"Attempt to close session raised a local exception: {e}")
145144

146-
self.open = False
145+
self.is_open = False

0 commit comments

Comments
 (0)