Skip to content

Commit c3ae658

Browse files
msrathore-dbclaude
andcommitted
Fix is_disconnect to handle closed connection errors
Enhanced is_disconnect() to catch databricks.sql.exc.Error (base class) and detect "closed connection" errors. This fixes pool_pre_ping failing when attempting to ping a closed connection. The default do_ping() tries to create a cursor, which raises Error with message "Cannot create cursor from closed connection" on closed connections. Now properly detects this as a disconnect error. Fixes: - test_pool_pre_ping_with_closed_connection - test_is_disconnect_handles_runtime_errors Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 1e47cb2 commit c3ae658

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/databricks/sqlalchemy/base.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def is_disconnect(self, e, connection, cursor):
357357
Returns:
358358
True if the error indicates a disconnect, False otherwise
359359
"""
360-
from databricks.sql.exc import InterfaceError, DatabaseError
360+
from databricks.sql.exc import InterfaceError, DatabaseError, Error
361361

362362
# InterfaceError: Client-side errors (e.g., connection already closed)
363363
if isinstance(e, InterfaceError):
@@ -368,6 +368,15 @@ def is_disconnect(self, e, connection, cursor):
368368
error_msg = str(e).lower()
369369
return "invalid" in error_msg and "handle" in error_msg
370370

371+
# Base Error class: Check for closed connection errors
372+
# This catches errors like "Cannot create cursor from closed connection"
373+
if isinstance(e, Error):
374+
error_msg = str(e).lower()
375+
return (
376+
"closed" in error_msg
377+
or "cannot create cursor" in error_msg
378+
)
379+
371380
return False
372381

373382
@reflection.cache

0 commit comments

Comments
 (0)