: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(linkedin_ads): treat 404 resource-not-found as non-retryable (#63736)
Tom Owers16160eb220d9
diff --git a/posthog/temporal/data_imports/sources/linkedin_ads/source.py b/posthog/temporal/data_imports/sources/linkedin_ads/source.pyindex e54ce1023cd0..d5ed401b683e 100644--- a/posthog/temporal/data_imports/sources/linkedin_ads/source.py+++ b/posthog/temporal/data_imports/sources/linkedin_ads/source.py@@ -47,6 +47,11 @@ class LinkedInAdsSource(ResumableSource[LinkedinAdsSourceConfig, LinkedInAdsResu# key value (volatile) followed by this stable type-coercion phrase. The account id is a# fixed config value, so retrying can't help — fail fast and tell the user to fix it."must be of type 'java.lang.Long'": "LinkedIn rejected the configured Account ID. It must be the numeric LinkedIn ad account ID (digits only). Please correct the Account ID in your source settings and re-sync.",+ # LinkedIn returns 404 RESOURCE_NOT_FOUND / "No virtual resource found" when the+ # account-scoped resource can't be resolved — the configured ad account doesn't exist+ # or PostHog no longer has access to it. Retrying can't fix a missing resource, so we+ # stop and surface a config-facing message instead of burning retries every schedule.+ "No virtual resource found": "LinkedIn could not find the configured ad account. Please check that the Account ID is correct and that PostHog still has access to it, then try again.",}@propertydiff --git a/posthog/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.py b/posthog/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.pyindex 6ef88b9ad423..823f974b20de 100644--- a/posthog/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.py+++ b/posthog/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.py@@ -85,3 +85,38 @@ class TestLinkedInAdsSource:def test_non_retryable_errors_does_not_match_unrelated(self, other_error):non_retryable_errors = self.source.get_non_retryable_errors()assert not any(key in other_error for key in non_retryable_errors)++ @pytest.mark.parametrize(+ "pattern,raised_message",+ [+ (+ "No virtual resource found",+ 'LinkedIn API error (404): {"status":404,"code":"RESOURCE_NOT_FOUND","message":"No virtual resource found"}',+ ),+ (+ "The token used in the request has expired",+ "LinkedIn API error (401): The token used in the request has expired",+ ),+ ],+ )+ def test_get_non_retryable_errors_pattern_recognised(self, pattern, raised_message):+ non_retryable_errors = self.source.get_non_retryable_errors()++ assert pattern in non_retryable_errors+ assert pattern in raised_message++ @pytest.mark.parametrize(+ "transient_message",+ [+ # Transient transport / 5xx failures must stay retryable — matching any of these would+ # disable the schema sync after a handful of recoverable blips.+ "LinkedIn API error (retryable, 500): Internal Server Error",+ "LinkedIn API error (retryable, 504): Gateway Timeout",+ "ConnectionError: HTTPSConnectionPool(host='api.linkedin.com', port=443): Max retries exceeded",+ "ReadTimeout: The read operation timed out",+ ],+ )+ def test_get_non_retryable_errors_does_not_match_transient_failures(self, transient_message):+ non_retryable_errors = self.source.get_non_retryable_errors()++ assert not any(pattern in transient_message for pattern in non_retryable_errors)