From a17283a1c2a96a46a06bd468ef7dddfc934052ff Mon Sep 17 00:00:00 2001 From: Levko Kravets Date: Tue, 27 Feb 2024 21:29:16 +0200 Subject: [PATCH] Clear `active_op_handle` when closing the cursor Signed-off-by: Levko Kravets --- src/databricks/sql/client.py | 7 +++++++ tests/unit/test_client.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/databricks/sql/client.py b/src/databricks/sql/client.py index c11c6399..ad5146d1 100644 --- a/src/databricks/sql/client.py +++ b/src/databricks/sql/client.py @@ -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 diff --git a/tests/unit/test_client.py b/tests/unit/test_client.py index c8b5100e..72f8e7d5 100644 --- a/tests/unit/test_client.py +++ b/tests/unit/test_client.py @@ -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__':