Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d869d0

Browse files
authored
Do not retry failing requests with status code 401 (databricks#408)
- Raises NonRecoverableNetworkError when request results in 401 status code Signed-off-by: Tor Hødnebø <[email protected]> Signed-off-by: Tor Hødnebø <[email protected]>
1 parent 93e207e commit 5d869d0

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release History
22

3+
# x.x.x (TBD)
4+
5+
- Don't retry requests that fail with code 401
6+
37
# 3.2.0 (2024-06-06)
48

59
- Update proxy authentication (databricks/databricks-sql-python#354 by @amir-haroun)

src/databricks/sql/auth/retry.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,8 @@ def should_retry(self, method: str, status_code: int) -> Tuple[bool, str]:
327327
default, this means ExecuteStatement is only retried for codes 429 and 503.
328328
This limit prevents automatically retrying non-idempotent commands that could
329329
be destructive.
330-
5. The request received a 403 response, because this can never succeed.
330+
5. The request received a 401 response, because this can never succeed.
331+
6. The request received a 403 response, because this can never succeed.
331332
332333
333334
Q: What about OSErrors and Redirects?
@@ -341,6 +342,11 @@ def should_retry(self, method: str, status_code: int) -> Tuple[bool, str]:
341342
if status_code == 200:
342343
return False, "200 codes are not retried"
343344

345+
if status_code == 401:
346+
raise NonRecoverableNetworkError(
347+
"Received 401 - UNAUTHORIZED. Confirm your authentication credentials."
348+
)
349+
344350
if status_code == 403:
345351
raise NonRecoverableNetworkError(
346352
"Received 403 - FORBIDDEN. Confirm your authentication credentials."

tests/e2e/common/retry_test_mixins.py

+13
Original file line numberDiff line numberDiff line change
@@ -421,3 +421,16 @@ def test_403_not_retried(self):
421421
with self.connection(extra_params=self._retry_policy) as conn:
422422
pass
423423
assert isinstance(cm.value.args[1], NonRecoverableNetworkError)
424+
425+
def test_401_not_retried(self):
426+
"""GIVEN the server returns a code 401
427+
WHEN the connector receives this response
428+
THEN nothing is retried and an exception is raised
429+
"""
430+
431+
# Code 401 is an Unauthorized error
432+
with mocked_server_response(status=401):
433+
with pytest.raises(RequestError) as cm:
434+
with self.connection(extra_params=self._retry_policy):
435+
pass
436+
assert isinstance(cm.value.args[1], NonRecoverableNetworkError)

0 commit comments

Comments
 (0)