Skip to content

Commit 1c58313

Browse files
author
Jesse Whitehouse
committed
Attempt to completely remove query_secret and send an empty UUID.
Signed-off-by: Jesse Whitehouse <[email protected]>
1 parent bf046ff commit 1c58313

File tree

3 files changed

+22
-39
lines changed

3 files changed

+22
-39
lines changed

src/databricks/sql/ae.py

+7-12
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ def __init__(
8787
thrift_backend: "ThriftBackend",
8888
connection: "Connection",
8989
query_id: UUID,
90-
query_secret: UUID,
9190
status: Optional[AsyncExecutionStatus] = AsyncExecutionStatus.UNKNOWN,
9291
execute_statement_response: Optional[
9392
Union[FakeExecuteStatementResponse, ttypes.TExecuteStatementResp]
@@ -96,7 +95,6 @@ def __init__(
9695
self._connection = connection
9796
self._thrift_backend = thrift_backend
9897
self.query_id = query_id
99-
self.query_secret = query_secret
10098
self.status = status
10199

102100
if execute_statement_response:
@@ -155,7 +153,7 @@ def _thrift_cancel_operation(self) -> None:
155153
def _thrift_get_operation_status(self) -> ttypes.TGetOperationStatusResp:
156154
"""Execute TGetOperationStatusReq
157155
158-
Raises an AsyncExecutionError if the query_id:query_secret pair is not found on the server.
156+
Raises an AsyncExecutionError if the query_id is not found on the server.
159157
"""
160158
try:
161159
return self._thrift_backend._poll_for_status(self.t_operation_handle)
@@ -166,10 +164,10 @@ def _thrift_get_operation_status(self) -> ttypes.TGetOperationStatusResp:
166164
) from e
167165

168166
def serialize(self) -> str:
169-
"""Return a string representing the query_id and secret of this AsyncExecution.
167+
"""Return a hex string representing the query_id of this AsyncExecution.
170168
171-
Use this to preserve a reference to the query_id and query_secret."""
172-
return f"{self.query_id}:{self.query_secret}"
169+
Use this to preserve a reference to the query_id"""
170+
return f"{self.query_id}"
173171

174172
def sync_status(self) -> None:
175173
"""Synchronise the status of this AsyncExecution with the server query execution state."""
@@ -212,7 +210,7 @@ def t_operation_handle(self) -> ttypes.TOperationHandle:
212210

213211
handle = ttypes.TOperationHandle(
214212
operationId=ttypes.THandleIdentifier(
215-
guid=self.query_id.bytes, secret=self.query_secret.bytes
213+
guid=self.query_id.bytes, secret=UUID(int=0).bytes
216214
),
217215
operationType=ttypes.TOperationType.EXECUTE_STATEMENT,
218216
hasResultSet=True,
@@ -238,7 +236,6 @@ def from_thrift_response(
238236
connection=connection,
239237
thrift_backend=thrift_backend,
240238
query_id=UUID(bytes=resp.operationHandle.operationId.guid),
241-
query_secret=UUID(bytes=resp.operationHandle.operationId.secret),
242239
status=_toperationstate_to_ae_status(
243240
resp.directResults.operationStatus.operationState
244241
),
@@ -251,19 +248,17 @@ def from_query_id_and_secret(
251248
connection: "Connection",
252249
thrift_backend: "ThriftBackend",
253250
query_id: UUID,
254-
query_secret: UUID,
255251
) -> "AsyncExecution":
256-
"""Return a valid AsyncExecution object from a query_id and query_secret.
252+
"""Return a valid AsyncExecution object from a query_id.
257253
258-
Raises an AsyncExecutionException if the query_id:query_secret pair is not found on the server.
254+
Raises an AsyncExecutionException if the query_id pair is not found on the server.
259255
"""
260256

261257
# build a copy of this execution
262258
ae = cls(
263259
connection=connection,
264260
thrift_backend=thrift_backend,
265261
query_id=query_id,
266-
query_secret=query_secret,
267262
)
268263
# check to make sure this is a valid one
269264
ae.sync_status()

src/databricks/sql/client.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,12 @@ def execute_async(
405405
)
406406

407407
def get_async_execution(
408-
self, query_id: Union[str, UUID], query_secret: Union[str, UUID]
408+
self, query_id: Union[str, UUID]
409409
) -> "AsyncExecution":
410410
"""Get an AsyncExecution object for an existing query.
411411
412412
Args:
413413
query_id: The query id of the query to retrieve
414-
query_secret: The query secret of the query to retrieve
415414
416415
Returns:
417416
An AsyncExecution object that can be used to poll for status and retrieve results.
@@ -422,16 +421,10 @@ def get_async_execution(
422421
else:
423422
_qid = UUID(hex=query_id)
424423

425-
if isinstance(query_secret, UUID):
426-
_qs = query_secret
427-
else:
428-
_qs = UUID(hex=query_secret)
429-
430424
return AsyncExecution.from_query_id_and_secret(
431425
connection=self,
432426
thrift_backend=self.thrift_backend,
433427
query_id=_qid,
434-
query_secret=_qs,
435428
)
436429

437430

tests/e2e/test_execute_async.py

+14-19
Original file line numberDiff line numberDiff line change
@@ -82,28 +82,24 @@ def test_cant_get_results_after_cancel(self, long_running_ae: AsyncExecution):
8282
def test_get_async_execution_can_check_status(
8383
self, long_running_ae: AsyncExecution
8484
):
85-
query_id, query_secret = str(long_running_ae.query_id), str(
86-
long_running_ae.query_secret
87-
)
85+
query_id = long_running_ae.serialize()
8886

8987
with self.connection() as conn:
90-
ae = conn.get_async_execution(query_id, query_secret)
88+
ae = conn.get_async_execution(query_id)
9189
assert ae.is_running
9290

9391
def test_get_async_execution_can_cancel_across_threads(
9492
self, long_running_ae: AsyncExecution
9593
):
96-
query_id, query_secret = str(long_running_ae.query_id), str(
97-
long_running_ae.query_secret
98-
)
94+
query_id = long_running_ae.serialize()
9995

100-
def cancel_query_in_separate_thread(query_id, query_secret):
96+
def cancel_query_in_separate_thread(query_id):
10197
with self.connection() as conn:
102-
ae = conn.get_async_execution(query_id, query_secret)
98+
ae = conn.get_async_execution(query_id)
10399
ae.cancel()
104100

105101
threading.Thread(
106-
target=cancel_query_in_separate_thread, args=(query_id, query_secret)
102+
target=cancel_query_in_separate_thread, args=(query_id)
107103
).start()
108104

109105
time.sleep(5)
@@ -154,30 +150,29 @@ def test_get_async_execution_with_badly_formed_query_id(self):
154150
ae = conn.get_async_execution("foo", "bar")
155151

156152
def test_serialize(self, long_running_ae: AsyncExecution):
157-
serialized = long_running_ae.serialize()
158-
query_id, query_secret = serialized.split(":")
153+
query_id = long_running_ae.serialize()
159154

160155
with self.connection() as conn:
161-
ae = conn.get_async_execution(query_id, query_secret)
156+
ae = conn.get_async_execution(query_id)
162157
assert ae.is_running
163158

164159
def test_get_async_execution_no_results_when_direct_results_were_sent(self):
165160
"""It remains to be seen whether results can be fetched repeatedly from a "picked up" execution."""
166161

167162
with self.connection() as conn:
168163
ae = conn.execute_async(DIRECT_RESULTS_QUERY, {"param": 1})
169-
query_id, query_secret = ae.serialize().split(":")
164+
query_id = ae.serialize()
170165
ae.get_result()
171166

172167
with self.connection() as conn:
173168
with pytest.raises(AsyncExecutionException, match="Query not found"):
174-
ae_late = conn.get_async_execution(query_id, query_secret)
169+
ae_late = conn.get_async_execution(query_id)
175170

176171
def test_get_async_execution_and_fetch_results(self, long_ish_ae: AsyncExecution):
177-
query_id, query_secret = long_ish_ae.serialize().split(":")
172+
query_id = long_ish_ae.serialize()
178173

179174
with self.connection() as conn:
180-
ae = conn.get_async_execution(query_id, query_secret)
175+
ae = conn.get_async_execution(query_id)
181176

182177
while ae.is_running:
183178
time.sleep(1)
@@ -194,8 +189,8 @@ def test_get_async_execution_twice(self):
194189
with self.connection() as conn_1, self.connection() as conn_2:
195190
ae_1 = conn_1.execute_async(LONG_ISH_QUERY)
196191

197-
query_id, query_secret = ae_1.serialize().split(":")
198-
ae_2 = conn_2.get_async_execution(query_id, query_secret)
192+
query_id = ae_1.serialize()
193+
ae_2 = conn_2.get_async_execution(query_id)
199194

200195
while ae_1.is_running:
201196
time.sleep(1)

0 commit comments

Comments
 (0)