@@ -336,35 +336,6 @@ def do_rollback(self, dbapi_connection):
336336 # Databricks SQL Does not support transactions
337337 pass
338338
339- def do_ping (self , dbapi_connection ):
340- """Test if a database connection is alive.
341-
342- This method is called by SQLAlchemy when pool_pre_ping=True to verify
343- connections are still valid before using them from the pool.
344-
345- This implementation improves upon SQLAlchemy's default do_ping() by
346- wrapping the cursor creation in a try block, which properly handles
347- cases where the connection is closed and cursor() itself raises an exception.
348-
349- Args:
350- dbapi_connection: A raw DBAPI connection (from databricks-sql-connector)
351-
352- Returns:
353- True if the connection is alive, False otherwise.
354- """
355- try :
356- cursor = dbapi_connection .cursor ()
357- try :
358- cursor .execute ("SELECT VERSION()" )
359- cursor .fetchone ()
360- return True
361- finally :
362- cursor .close ()
363- except Exception :
364- # Any exception means the connection is dead
365- # SQLAlchemy will discard it and create a new one
366- return False
367-
368339 def is_disconnect (self , e , connection , cursor ):
369340 """Determine if an exception indicates the connection was lost.
370341
@@ -373,9 +344,10 @@ def is_disconnect(self, e, connection, cursor):
373344 returns True, SQLAlchemy will invalidate the connection and create a new
374345 one for the next operation.
375346
376- This is complementary to do_ping():
377- - do_ping() is proactive: checks connection health BEFORE queries
378- - is_disconnect() is reactive: classifies errors AFTER they occur
347+ This method is also used by SQLAlchemy's default do_ping() implementation
348+ when pool_pre_ping=True. If do_ping() encounters an exception, it calls
349+ is_disconnect() to classify the error and determine whether to invalidate
350+ the connection.
379351
380352 Args:
381353 e: The exception that was raised
0 commit comments