Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(data-imports): retry a 408 from the shared REST client (#123438)

Tom Owers87757ed5af22
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/rest_client.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/rest_client.py
index edeac354f1cc..d1f2ac4d8ab8 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/rest_client.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/rest_client.py
@@ -695,7 +695,11 @@ class RESTClient:
)
)
- if response.status_code == 429 or response.status_code >= 500:
+ # 408 joins 429/5xx here because it's the same signal as both: the server itself, not our
+ # transport, is telling us to come back later. Individual sources already special-case it
+ # this way (openrouter, datadog, hubspot, ...) when they hand-roll their own transport; the
+ # shared client should give every REST-framework source the same behavior by default.
+ if response.status_code in (408, 429) or response.status_code >= 500:
# `_safe_url` drops the query string entirely: `_redact` only masks the raw secret, not
# the percent-encoded form an `api_key` query credential takes in the URL, so scheme/
# host/path-only is what keeps an encoded credential out of the persisted `latest_error`.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/tests/test_rest_client.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/tests/test_rest_client.py
index 9e5e1c55dd69..a3d26e7d0a37 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/tests/test_rest_client.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/rest_source/tests/test_rest_client.py
@@ -351,6 +351,7 @@ class TestRESTClient:
[
pytest.param(lambda: _make_response({"error": "rate limited"}, status_code=429), id="429"),
pytest.param(lambda: _make_response({"error": "internal"}, status_code=500), id="500"),
+ pytest.param(lambda: _make_response({"error": "timeout"}, status_code=408), id="408"),
pytest.param(_make_truncated_response, id="truncated_json"),
],
)
@@ -359,7 +360,7 @@ class TestRESTClient:
"products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.rest_client.make_tracked_session"
)
def test_send_request_retries_transient_error_then_succeeds(self, MockSession, mock_sleep, make_error) -> None:
- # A 429, a 5xx, and a truncated body are all transient: retry, then succeed.
+ # A 429, a 5xx, a 408, and a truncated body are all transient: retry, then succeed.
mock_session = MockSession.return_value
mock_session.headers = {}
mock_session.prepare_request.return_value = MagicMock()