Skip to content

Commit 887a9e0

Browse files
committed
Added unit tests and modified the code
1 parent 8d20b79 commit 887a9e0

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/databricks/sql/auth/retry.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class CommandType(Enum):
3232
CLOSE_SESSION = "CloseSession"
3333
CLOSE_OPERATION = "CloseOperation"
3434
GET_OPERATION_STATUS = "GetOperationStatus"
35+
FETCH_RESULTS_ORIENTATION_FETCH_NEXT = "FetchResultsOrientation_FETCH_NEXT"
3536
OTHER = "Other"
3637

3738
@classmethod
@@ -362,6 +363,12 @@ def should_retry(self, method: str, status_code: int) -> Tuple[bool, str]:
362363
if status_code == 501:
363364
raise NonRecoverableNetworkError("Received code 501 from server.")
364365

366+
if self.command_type == CommandType.FETCH_RESULTS_ORIENTATION_FETCH_NEXT:
367+
return (
368+
False,
369+
"FetchResults with FETCH_NEXT orientation are not idempotent and is not retried",
370+
)
371+
365372
# Request failed and this method is not retryable. We only retry POST requests.
366373
if not self._is_method_retryable(method):
367374
return False, "Only POST requests are retried"

src/databricks/sql/thrift_backend.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,15 @@ def attempt_request(attempt):
374374

375375
# These three lines are no-ops if the v3 retry policy is not in use
376376
if self.enable_v3_retries:
377+
# Not to retry when FetchResults has orientation as FETCH_NEXT as it is not idempotent
378+
if this_method_name == "FetchResults":
379+
this_method_name += (
380+
"Orientation_"
381+
+ ttypes.TFetchOrientation._VALUES_TO_NAMES[
382+
request.orientation
383+
]
384+
)
385+
377386
this_command_type = CommandType.get(this_method_name)
378387
self._transport.set_retry_command_type(this_command_type)
379388
self._transport.startRetryTimer()

tests/unit/test_retry.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,9 @@ def test_sleep__retry_after_present(self, t_mock, retry_policy, error_history):
8484
retry_policy.history = [error_history, error_history, error_history]
8585
retry_policy.sleep(HTTPResponse(status=503, headers={"Retry-After": "3"}))
8686
t_mock.assert_called_with(3)
87+
88+
def test_not_retryable__fetch_results_orientation_fetch_next(self, retry_policy):
89+
HTTP_STATUS_CODES = [200, 429, 503, 504]
90+
retry_policy.command_type = CommandType.FETCH_RESULTS_ORIENTATION_FETCH_NEXT
91+
for status_code in HTTP_STATUS_CODES:
92+
assert not retry_policy.is_retry("METHOD_NAME", status_code=status_code)

0 commit comments

Comments
 (0)