Skip to content

Commit

Permalink
Clear active_op_handle when closing the cursor
Browse files Browse the repository at this point in the history
Signed-off-by: Levko Kravets <levko.ne@gmail.com>
  • Loading branch information
kravets-levko committed Feb 27, 2024
1 parent 6815d45 commit a17283a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/databricks/sql/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,11 +1005,18 @@ def cancel(self) -> None:
def close(self) -> None:
"""Close cursor"""
self.open = False
self.active_op_handle = None
if self.active_result_set:
self._close_and_clear_active_result_set()

@property
def query_id(self) -> Optional[str]:
"""
This attribute is an identifier of last executed query.
This attribute will be ``None`` if the cursor has not had an operation
invoked via the execute method yet, or if cursor was closed.
"""
if self.active_op_handle is not None:
return str(UUID(bytes=self.active_op_handle.operationId.guid))
return None
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ def test_access_current_query_id(self):
self.assertEqual(cursor.query_id.upper(), operation_id.upper())

cursor.close()
self.assertEqual(cursor.query_id.upper(), operation_id.upper())
self.assertIsNone(cursor.query_id)


if __name__ == '__main__':
Expand Down

0 comments on commit a17283a

Please sign in to comment.