Skip to content

Commit 1d4da9a

Browse files
author
Jesse
authored
Don't retry network requests that fail with code 403 (#373)
* Don't retry requests that fail with 404 Signed-off-by: Jesse Whitehouse <jesse@whitehouse.dev> * Fix lint error Signed-off-by: Jesse Whitehouse <jesse@whitehouse.dev> --------- Signed-off-by: Jesse Whitehouse <jesse@whitehouse.dev>
1 parent c103352 commit 1d4da9a

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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?
@@ -338,6 +339,11 @@ def should_retry(self, method: str, status_code: int) -> Tuple[bool, str]:
338339
if status_code == 200:
339340
return False, "200 codes are not retried"
340341

342+
if status_code == 403:
343+
raise NonRecoverableNetworkError(
344+
"Received 403 - FORBIDDEN. Confirm your authentication credentials."
345+
)
346+
341347
# Request failed and server said NotImplemented. This isn't recoverable. Don't retry.
342348
if status_code == 501:
343349
raise NonRecoverableNetworkError("Received code 501 from server.")

tests/e2e/common/retry_test_mixins.py

Lines changed: 14 additions & 0 deletions
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)