: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(meta_ads): treat deleted integration as non-retryable (#64303)
Tom Owersaa650e54c6aa
diff --git a/posthog/temporal/data_imports/sources/meta_ads/source.py b/posthog/temporal/data_imports/sources/meta_ads/source.pyindex ce573bf09a10..2460419e0dfa 100644--- a/posthog/temporal/data_imports/sources/meta_ads/source.py+++ b/posthog/temporal/data_imports/sources/meta_ads/source.py@@ -40,6 +40,14 @@ class MetaAdsSource(ResumableSource[MetaAdsSourceConfig, MetaAdsResumeConfig]):def get_non_retryable_errors(self) -> dict[str, str | None]:return {"Failed to refresh token for Meta Ads integration. Please re-authorize the integration.": None,+ # The data warehouse source still references a `meta_ads_integration_id` whose+ # Integration row no longer exists for the team (the integration was deleted or+ # de-authorized). `get_integration` then raises Django's `Integration.DoesNotExist`+ # ("Integration matching query does not exist."); retrying can never make the row+ # reappear — the only fix is the user reconnecting the integration.+ "Integration matching query does not exist.": (+ "The Meta Ads integration for this source no longer exists. Please reconnect the Meta Ads integration."+ ),# Permanent auth/permission failures from the Graph API (e.g. revoked or expired# access tokens, checkpoint-required, invalidated sessions, permission denials).# `meta_ads._raise_meta_api_error` prefixes these with this exact message.diff --git a/posthog/temporal/data_imports/sources/meta_ads/test_meta_ads.py b/posthog/temporal/data_imports/sources/meta_ads/test_meta_ads.pyindex 7efe9e3374cc..425b35dad861 100644--- a/posthog/temporal/data_imports/sources/meta_ads/test_meta_ads.py+++ b/posthog/temporal/data_imports/sources/meta_ads/test_meta_ads.py@@ -780,6 +780,9 @@ class TestNonRetryableErrors:[# Token refresh failure raised by get_integration."Failed to refresh token for Meta Ads integration. Please re-authorize the integration.",+ # Integration row deleted/de-authorized while the source still references it —+ # get_integration raises Django's Integration.DoesNotExist with this message.+ "Integration matching query does not exist.",# 400 from Meta when the ad account no longer belongs to the authorised user.'Meta API request failed: 400 - {"error":{"message":"(#200) Ad account owner has NOT granted ads_management or ads_read permission.","type":"OAuthException","code":200}}',# 400 when a specific endpoint cannot be accessed with the granted permissions.