: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(pinterest_ads): classify transient 5xx/429 as retryable errors (#107808)
Tom Owersf455ebe7651f
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/source.pyindex 389da74a24f0..27a5e3b580f1 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/source.py@@ -69,6 +69,22 @@ class PinterestAdsSource(ResumableSource[PinterestAdsSourceConfig, PinterestAdsR"404 Client Error": "Pinterest Ads resource not found. Please check your ad account ID.",}+ def get_retryable_errors(self) -> set[str]:+ # `build_session` mounts the shared tracked transport, whose adapter already retries+ # GET requests on these statuses in-process (see DEFAULT_RETRY in+ # sources/common/http/transport.py) before `raise_for_status()` can raise. A plain+ # `requests.HTTPError` only reaches `_make_request` once that budget is exhausted, so+ # Pinterest is rate-limiting us (429) or briefly unavailable (5xx) — both transient and+ # self-recovering. Let Temporal retry the whole activity instead of reporting this as an+ # unclassified error every run.+ return {+ "429 Client Error",+ "500 Server Error",+ "502 Server Error",+ "503 Server Error",+ "504 Server Error",+ }+@propertydef get_source_config(self) -> SourceConfig:return SourceConfig(diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/tests/test_pinterest_ads.py b/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/tests/test_pinterest_ads.pyindex 979dbfc93950..20113b587034 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/tests/test_pinterest_ads.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/pinterest_ads/tests/test_pinterest_ads.py@@ -320,6 +320,31 @@ class TestMakeRequestErrorHandling:f"HTTP {status_code} error message '{error_msg}' does not match any non-retryable pattern")+ @pytest.mark.parametrize("status_code", [429, 500, 502, 503, 504])+ def test_transient_errors_are_retryable(self, status_code):+ # These are the statuses the shared tracked transport already retries in-process; once+ # that budget is exhausted the error must stay retryable (and out of the non-retryable+ # set) so a self-recovering blip isn't reported as an unclassified error.+ error_class = "Client Error" if status_code == 429 else "Server Error"+ mock_response = mock.MagicMock()+ mock_response.status_code = status_code+ mock_response.raise_for_status.side_effect = requests.HTTPError(+ f"{status_code} {error_class}: for url: https://api.pinterest.com/v5/test",+ response=mock_response,+ )++ mock_session = mock.MagicMock()+ mock_session.get.return_value = mock_response++ source = PinterestAdsSource()++ with pytest.raises(requests.HTTPError) as exc_info:+ _make_request(mock_session, "https://api.pinterest.com/v5/test")++ error_msg = str(exc_info.value)+ assert any(pattern in error_msg for pattern in source.get_retryable_errors())+ assert not any(pattern in error_msg for pattern in source.get_non_retryable_errors())+@pytest.mark.parametrize("status_code", [200, 201])def test_success_returns_json(self, status_code):mock_response = mock.MagicMock()