File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1713,9 +1713,13 @@ def cancel(self) -> None:
17131713 def close (self ) -> None :
17141714 """Close cursor"""
17151715 self .open = False
1716- self .active_command_id = None
1717- if self .active_result_set :
1718- self ._close_and_clear_active_result_set ()
1716+ try :
1717+ if self .active_result_set :
1718+ self ._close_and_clear_active_result_set ()
1719+ elif self .active_command_id is not None :
1720+ self .backend .close_command (self .active_command_id )
1721+ finally :
1722+ self .active_command_id = None
17191723
17201724 @property
17211725 def query_id (self ) -> Optional [str ]:
Original file line number Diff line number Diff line change @@ -280,6 +280,33 @@ def test_context_manager_closes_cursor(self):
280280 cursor .close = mock_close
281281 mock_close .assert_called_once_with ()
282282
283+ def test_close_closes_active_command_without_result_set (self ):
284+ mock_backend = Mock ()
285+ mock_command_id = Mock (spec = CommandId )
286+ cursor = client .Cursor (Mock (), mock_backend )
287+ cursor .active_command_id = mock_command_id
288+
289+ cursor .close ()
290+
291+ mock_backend .close_command .assert_called_once_with (mock_command_id )
292+ self .assertIsNone (cursor .active_command_id )
293+ self .assertIsNone (cursor .active_result_set )
294+
295+ def test_close_delegates_to_active_result_set_without_double_closing_command (self ):
296+ mock_backend = Mock ()
297+ mock_result_set = Mock ()
298+ mock_command_id = Mock (spec = CommandId )
299+ cursor = client .Cursor (Mock (), mock_backend )
300+ cursor .active_result_set = mock_result_set
301+ cursor .active_command_id = mock_command_id
302+
303+ cursor .close ()
304+
305+ mock_result_set .close .assert_called_once_with ()
306+ mock_backend .close_command .assert_not_called ()
307+ self .assertIsNone (cursor .active_command_id )
308+ self .assertIsNone (cursor .active_result_set )
309+
283310 def dict_product (self , dicts ):
284311 """
285312 Generate cartesion product of values in input dictionary, outputting a dictionary
You can’t perform that action at this time.
0 commit comments