File tree Expand file tree Collapse file tree 2 files changed +8
-5
lines changed Expand file tree Collapse file tree 2 files changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -317,7 +317,9 @@ 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- return self .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
321323
322324 def cursor (
323325 self ,
Original file line number Diff line number Diff 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 .is_open = False
32+ self .open = False
3333 self .host = server_hostname
3434 self .port = kwargs .get ("_port" , 443 )
3535
@@ -77,12 +77,13 @@ def __init__(
7777 _use_arrow_native_complex_types = _use_arrow_native_complex_types ,
7878 ** kwargs ,
7979 )
80+
8081 self ._open_session_resp = self .thrift_backend .open_session (
8182 session_configuration , catalog , schema
8283 )
8384 self ._session_handle = self ._open_session_resp .sessionHandle
8485 self .protocol_version = self .get_protocol_version (self ._open_session_resp )
85- self .is_open = True
86+ self .open = True
8687 logger .info ("Successfully opened session " + str (self .get_session_id_hex ()))
8788
8889 @staticmethod
@@ -121,7 +122,7 @@ def get_session_id_hex(self):
121122 def close (self ) -> None :
122123 """Close the underlying session."""
123124 logger .info (f"Closing session { self .get_session_id_hex ()} " )
124- if not self .is_open :
125+ if not self .open :
125126 logger .debug ("Session appears to have been closed already" )
126127 return
127128
@@ -142,4 +143,4 @@ def close(self) -> None:
142143 except Exception as e :
143144 logger .error (f"Attempt to close session raised a local exception: { e } " )
144145
145- self .is_open = False
146+ self .open = False
You can’t perform that action at this time.
0 commit comments