Skip to content

Commit 44f3697

Browse files
committed
fix: Check if connection initialized when deleting Connection
The session is cleaned up when deleting a connection. But, if the connection was not fully initialized (e.g. due to a connection error) then no session will be set. This will cause __del__ to fail and warnings to be printed to stderr. We can avoid this by checking if session is set and short-circuiting before checking if the session is open. Signed-off-by: Tomás Farías <tomas@tomasfarias.dev>
1 parent 9fe7356 commit 44f3697

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/databricks/sql/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ def __exit__(self, exc_type, exc_value, traceback):
434434
self.close()
435435

436436
def __del__(self):
437-
if self.open:
437+
initialized = hasattr(self, "session")
438+
if initialized and self.open:
438439
logger.debug(
439440
"Closing unclosed connection for session "
440441
"{}".format(self.get_session_id_hex())

0 commit comments

Comments
 (0)