Skip to content

Commit a50ec1f

Browse files
committed
Don't retry requests that fail with 404
1 parent c103352 commit a50ec1f

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
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 403
6+
37
# 3.1.0 (2024-02-16)
48

59
- Revert retry-after behavior to be exponential backoff (#349)

src/databricks/sql/auth/retry.py

+4
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ def should_retry(self, method: str, status_code: int) -> Tuple[bool, str]:
325325
default, this means ExecuteStatement is only retried for codes 429 and 503.
326326
This limit prevents automatically retrying non-idempotent commands that could
327327
be destructive.
328+
5. The request received a 403 response, because this can never succeed.
328329
329330
330331
Q: What about OSErrors and Redirects?
@@ -337,6 +338,9 @@ def should_retry(self, method: str, status_code: int) -> Tuple[bool, str]:
337338
# Request succeeded. Don't retry.
338339
if status_code == 200:
339340
return False, "200 codes are not retried"
341+
342+
if status_code == 403:
343+
raise NonRecoverableNetworkError("Received 403 - FORBIDDEN. Confirm your authentication credentials.")
340344

341345
# Request failed and server said NotImplemented. This isn't recoverable. Don't retry.
342346
if status_code == 501:

tests/e2e/common/retry_test_mixins.py

+14
Original file line numberDiff line numberDiff line change
@@ -407,3 +407,17 @@ def test_retry_max_redirects_exceeds_max_attempts_count_warns_user(self, caplog)
407407
def test_retry_legacy_behavior_warns_user(self, caplog):
408408
with self.connection(extra_params={**self._retry_policy, "_enable_v3_retries": False}):
409409
assert "Legacy retry behavior is enabled for this connection." in caplog.text
410+
411+
412+
def test_403_not_retried(self):
413+
"""GIVEN the server returns a code 403
414+
WHEN the connector receives this response
415+
THEN nothing is retried and an exception is raised
416+
"""
417+
418+
# Code 403 is a Forbidden error
419+
with mocked_server_response(status=403):
420+
with pytest.raises(RequestError) as cm:
421+
with self.connection(extra_params=self._retry_policy) as conn:
422+
pass
423+
assert isinstance(cm.value.args[1], NonRecoverableNetworkError)

0 commit comments

Comments
 (0)