: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 invalid Account ID 400 as non-retryable (#63686)
Tom Owers4ea62e7a062b
diff --git a/posthog/temporal/data_imports/sources/linkedin_ads/source.py b/posthog/temporal/data_imports/sources/linkedin_ads/source.pyindex d34b8d93a443..e54ce1023cd0 100644--- a/posthog/temporal/data_imports/sources/linkedin_ads/source.py+++ b/posthog/temporal/data_imports/sources/linkedin_ads/source.py@@ -43,6 +43,10 @@ class LinkedInAdsSource(ResumableSource[LinkedinAdsSourceConfig, LinkedInAdsResureturn {"REVOKED_ACCESS_TOKEN": None,"The token used in the request has expired": "Failed to refresh token for LinkedIn Ads integration. Please re-authorize the integration.",+ # LinkedIn rejects a non-numeric Account ID with a 400 whose message names the offending+ # 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.",}@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 5d67abe2c86c..6ef88b9ad423 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@@ -1,3 +1,4 @@+import pytestfrom unittest import mockfrom posthog.temporal.data_imports.sources.generated_configs import LinkedinAdsSourceConfig@@ -59,3 +60,28 @@ class TestLinkedInAdsSource:assert "Failed to validate LinkedIn Ads credentials" in error_messageassert "Database error" in error_messagemock_capture_exception.assert_called_once()++ @pytest.mark.parametrize(+ "observed_error",+ [+ # A non-numeric Account ID raises this 400 — the quoted key value is volatile, the+ # type-coercion phrase is the stable part we match on.+ 'LinkedIn API error (400): {"message":"Key value \'Reed%20Lnkedin\' must be of type \'java.lang.Long\'","status":400}',+ 'LinkedIn API error (400): {"message":"Key value \'LI\' must be of type \'java.lang.Long\'","status":400}',+ ],+ )+ def test_non_retryable_errors_match_invalid_account_id(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",+ [+ # Transient transport / 5xx errors must stay retryable.+ "LinkedIn API error (retryable, 503): service unavailable",+ 'LinkedIn daily rate limit reached (429): {"message":"throttled","status":429}',+ ],+ )+ 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)