File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -181,12 +181,11 @@ def close(self) -> None:
181
181
self ._close ()
182
182
183
183
def _close (self , close_cursors = True ) -> None :
184
- self .thrift_backend .close_session (self ._session_handle )
185
- self .open = False
186
-
187
184
if close_cursors :
188
185
for cursor in self ._cursors :
189
186
cursor .close ()
187
+ self .thrift_backend .close_session (self ._session_handle )
188
+ self .open = False
190
189
191
190
def commit (self ):
192
191
"""No-op because Databricks does not support transactions"""
Original file line number Diff line number Diff line change @@ -544,6 +544,32 @@ def test_decimal_not_returned_as_strings_arrow(self):
544
544
decimal_type = arrow_df .field (0 ).type
545
545
self .assertTrue (pyarrow .types .is_decimal (decimal_type ))
546
546
547
+ def test_close_connection_closes_cursors (self ):
548
+
549
+ from databricks .sql .thrift_api .TCLIService import ttypes
550
+
551
+ with self .connection () as conn :
552
+ cursor = conn .cursor ()
553
+ cursor .execute ('SELECT id, id `id2`, id `id3` FROM RANGE(1000000) order by RANDOM()' )
554
+ ars = cursor .active_result_set
555
+
556
+ # We must manually run this check because thrift_backend always forces `has_been_closed_server_side` to True
557
+
558
+ # Cursor op state should be open before connection is closed
559
+ status_request = ttypes .TGetOperationStatusReq (operationHandle = ars .command_id , getProgressUpdate = False )
560
+ op_status_at_server = ars .thrift_backend ._client .GetOperationStatus (status_request )
561
+ assert op_status_at_server .operationState != ttypes .TOperationState .CLOSED_STATE
562
+
563
+ conn .close ()
564
+
565
+ # When connection closes, any cursor operations should no longer exist at the server
566
+ with self .assertRaises (thrift .Thrift .TApplicationException ) as cm :
567
+ op_status_at_server = ars .thrift_backend ._client .GetOperationStatus (status_request )
568
+ if hasattr (cm , "exception" ):
569
+ assert "RESOURCE_DOES_NOT_EXIST" in cm .exception .message
570
+
571
+
572
+
547
573
548
574
# use a RetrySuite to encapsulate these tests which we'll typically want to run together; however keep
549
575
# the 429/503 subsuites separate since they execute under different circumstances.
You can’t perform that action at this time.
0 commit comments