Skip to content

Commit c1d53d2

Browse files
madhav-dbvarun-edachali-dbx
authored andcommitted
Enhance Cursor close handling and context manager exception management to prevent server side resource leaks (#554)
* Enhance Cursor close handling and context manager exception management * tests * fmt * Fix Cursor.close() to properly handle CursorAlreadyClosedError * Remove specific test message from Cursor.close() error handling * Improve error handling in connection and cursor context managers to ensure proper closure during exceptions, including KeyboardInterrupt. Add tests for nested cursor management and verify operation closure on server-side errors. * add * add Signed-off-by: varun-edachali-dbx <[email protected]>
1 parent ff78b5f commit c1d53d2

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tests/unit/test_client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,15 @@ def test_context_manager_closes_cursor(self):
218218
finally:
219219
cursor.close.assert_called()
220220

221+
connection = databricks.sql.connect(**self.DUMMY_CONNECTION_ARGS)
222+
connection.close = Mock()
223+
try:
224+
with self.assertRaises(KeyboardInterrupt):
225+
with connection:
226+
raise KeyboardInterrupt("Simulated interrupt")
227+
finally:
228+
connection.close.assert_called()
229+
221230
def dict_product(self, dicts):
222231
"""
223232
Generate cartesion product of values in input dictionary, outputting a dictionary

0 commit comments

Comments
 (0)