: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 (#63726)
Tom Owersfc2419ca3580
diff --git a/posthog/temporal/data_imports/sources/linkedin_ads/source.py b/posthog/temporal/data_imports/sources/linkedin_ads/source.pyindex 02b7e26027e2..883d0cb6ca10 100644--- a/posthog/temporal/data_imports/sources/linkedin_ads/source.py+++ b/posthog/temporal/data_imports/sources/linkedin_ads/source.py@@ -47,11 +47,10 @@ 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.",+ # LinkedIn returns a 404 with this stable error code when the requested ad account /+ # resource can't be resolved — typically a deleted account, a wrong Account ID, or lost+ # access. Retrying can't recover it, so stop syncing instead of looping the 404.+ "RESOURCE_NOT_FOUND": "LinkedIn could not find the requested ad account. It may have been deleted, the configured Account ID may be wrong, or PostHog may have lost access. Check the Account ID and re-authorize the LinkedIn Ads integration.",# The Account ID is a free-text field. A malformed value (a profile URL, a name, stray# whitespace) makes LinkedIn reject the `urn:li:sponsoredAccount:<id>` accounts param with# a deterministic 400 ("...is invalid. Reason: Deserializing output ... failed"). Retryingdiff --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 075ef9b3ff4b..0d85162130c8 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@@ -17,6 +17,30 @@ class TestLinkedInAdsSource:self.team_id = 123self.config = LinkedinAdsSourceConfig(linkedin_ads_integration_id=456, account_id="789")+ @pytest.mark.parametrize(+ "observed_error",+ [+ 'LinkedIn API error (404): {"status":404,"code":"RESOURCE_NOT_FOUND","message":"No virtual resource found"}',+ "REVOKED_ACCESS_TOKEN",+ "The token used in the request has expired",+ ],+ )+ def test_non_retryable_errors_match_upstream_failures(self, observed_error):+ non_retryable_errors = self.source.get_non_retryable_errors()+ assert any(key in observed_error for key in non_retryable_errors)++ @pytest.mark.parametrize(+ "other_error",+ [+ 'LinkedIn API error (retryable, 500): {"message":"Internal Server Error"}',+ 'LinkedIn API error (retryable, 429): {"message":"Too many requests"}',+ "Connection reset by peer",+ ],+ )+ def test_non_retryable_errors_does_not_match_transient(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)+def test_validate_credentials_missing_account_id(self):"""Test credential validation with missing account ID."""invalid_config = LinkedinAdsSourceConfig(linkedin_ads_integration_id=456, account_id="")@@ -89,41 +113,6 @@ class TestLinkedInAdsSource: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)-@pytest.mark.parametrize("invalid_account_id",[