: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(apple-search-ads): classify transient API 5xx and 429 as retryable (#91256)
Tom Owers5e844e95411e
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/source.pyindex ecd2c78210b8..f1daf1635f46 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/source.py@@ -82,6 +82,25 @@ class AppleSearchAdsSource(ResumableSource[AppleSearchAdsSourceConfig, AppleSear"Could not sign the Apple Ads client secret": "The private key isn't a valid unencrypted EC (P-256) PEM. Paste the key you generated for your Apple Ads API client and reconnect.",}+ def get_retryable_errors(self) -> set[str]:+ # Apple's transport already retries these statuses in-process (see the+ # `status_forcelist` on `APPLE_SEARCH_ADS_RETRY`) with backoff, so one only reaches+ # here once that budget is exhausted — Apple is rate-limiting us (429) or its API is+ # briefly unavailable (5xx). Both are transient and self-recovering, so let Temporal+ # retry the whole activity. Unlike the shared REST engine, this source has its own+ # client, so `raise_for_status()` surfaces a plain `requests.HTTPError` that no+ # `RESTClientRetryableError` type-check catches; without this classification the+ # benign, self-recovering failure is logged at `exception` and reported as an+ # unclassified error every run. Match the code-anchored fragment, not the volatile+ # reason phrase or per-request URL.+ 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/apple_search_ads/tests/test_apple_search_ads_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/tests/test_apple_search_ads_source.pyindex 543a56dcb10a..ca61b4fe6239 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/tests/test_apple_search_ads_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/tests/test_apple_search_ads_source.py@@ -20,7 +20,10 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.apple_searfrom products.warehouse_sources.backend.temporal.data_imports.sources.apple_search_ads.source import (AppleSearchAdsSource,)-from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import VersionDeprecation+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import (+ VersionDeprecation,+ error_message_matches,+)from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.applesearchads import (AppleSearchAdsSourceConfig,@@ -114,6 +117,27 @@ class TestAppleSearchAdsSource:assert any(str(status) in key and host in key for key in errors)assert all(message for message in errors.values())+ @parameterized.expand(+ [+ (+ "rate_limited",+ "429 Client Error: Too Many Requests for url: https://api.searchads.apple.com/api/v5/reports",+ ),+ (+ "service_unavailable",+ "503 Server Error: Service Temporarily Unavailable for url: https://api.searchads.apple.com/api/v5/targetingkeywords/find",+ ),+ ("bad_gateway", "502 Server Error: Bad Gateway for url: https://api.ads.apple.com/v1/campaigns"),+ ("gateway_timeout", "504 Server Error: Gateway Timeout for url: https://api.ads.apple.com/v1/reports"),+ ]+ )+ def test_transient_api_statuses_are_retryable(self, _name: str, error_msg: str) -> None:+ # These are the statuses the transport already retries; once exhausted they must stay+ # retryable (and out of the non-retryable set) so a self-recovering blip isn't reported+ # as an unclassified error and the sync isn't disabled.+ assert error_message_matches(error_msg, self.source.get_retryable_errors())+ assert not error_message_matches(error_msg, self.source.get_non_retryable_errors().keys())+def test_get_resumable_source_manager_is_namespaced_per_schema(self) -> None:inputs = mock.MagicMock()inputs.schema_name = "campaign_report"