Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Retry all 5xx status codes #2035

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions singer_sdk/streams/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def requests_session(self) -> requests.Session:
def validate_response(self, response: requests.Response) -> None:
"""Validate HTTP response.

Checks for error status codes and wether they are fatal or retriable.
Checks for error status codes and whether they are fatal or retriable.

In case an error is deemed transient and can be safely retried, then this
method should raise an :class:`singer_sdk.exceptions.RetriableAPIError`.
Expand Down Expand Up @@ -179,9 +179,7 @@ def validate_response(self, response: requests.Response) -> None:
"""
if (
response.status_code in self.extra_retry_statuses
or HTTPStatus.INTERNAL_SERVER_ERROR
<= response.status_code
<= max(HTTPStatus)
or response.status_code >= HTTPStatus.INTERNAL_SERVER_ERROR
):
msg = self.response_error_message(response)
raise RetriableAPIError(msg, response)
Expand Down
10 changes: 9 additions & 1 deletion tests/core/rest/test_backoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ def custom_validation_stream(rest_tap):
match=r"503 Server Error: Service Unavailable for path: /dummy",
),
),
(
521, # Cloudflare custom status code higher than max(HTTPStatus)
"Web Server Is Down",
pytest.raises(
RetriableAPIError,
match=r"521 Server Error: Web Server Is Down for path: /dummy",
),
),
(
429,
"Too Many Requests",
Expand All @@ -84,7 +92,7 @@ def custom_validation_stream(rest_tap):
),
(200, "OK", nullcontext()),
],
ids=["client-error", "server-error", "rate-limited", "ok"],
ids=["client-error", "server-error", "server-error", "rate-limited", "ok"],
)
def test_status_code_api(basic_rest_stream, status_code, reason, expectation):
fake_response = requests.Response()
Expand Down
Loading