: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): stop retrying a missing-permissions API error (#101322)
Tom Owersff2848250b3d
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/source.pyindex d9b7549813d9..492102a030b9 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/source.py@@ -134,6 +134,13 @@ class MetaAdsSource(ResumableSource[MetaAdsSourceConfig, MetaAdsResumeConfig], O"required to read your ads data. Please reconnect the Meta Ads integration and grant ""all requested permissions."),+ # Graph API code 100: "Missing perms" — the shorter, generic sibling of the message+ # above for the same missing-permission condition on a specific field or endpoint.+ "Missing perms": (+ "Meta blocked this request because the connected account is missing a permission "+ "required to read your ads data. Please reconnect the Meta Ads integration and grant "+ "all requested permissions."+ ),# Graph API code 200: "Requires business_management permission to manage the object."# Distinct from the generic re-authorize message above — re-authorizing can never grant# this scope, since the Meta OAuth consent only requests `ads_read` (seediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/test_meta_ads.py b/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/test_meta_ads.pyindex d09a023dd90c..d7b112b40475 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/test_meta_ads.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/test_meta_ads.py@@ -1343,6 +1343,8 @@ class TestNonRetryableErrors:'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.'Meta API request failed: 400 - {"error":{"message":"(#100) This endpoint cannot be loaded due to missing permissions."}}',+ # 400 with the shorter, generic sibling message for the same missing-permission condition.+ 'Meta API request failed: 400 - {"error":{"message":"(#100) Missing perms","type":"OAuthException","code":100}}',# 400 when a business_management-gated field is requested without that scope.'Meta API request failed: 400 - {"error":{"message":"(#200) Requires business_management permission to manage the object.","type":"OAuthException","code":200}}',# 400 when the source's configured attribution windows include a value Meta's@@ -1373,6 +1375,15 @@ class TestNonRetryableErrors:f"Meta Ads error '{error_message}' does not match any non-retryable pattern")+ def test_missing_perms_has_reconnect_guidance(self) -> None:+ # `error_message` isn't surfaced to the user as-is — the friendly value here is, so a+ # blank or wrong one would leak the raw Graph API JSON instead of actionable guidance.+ assert MetaAdsSource().get_non_retryable_errors()["Missing perms"] == (+ "Meta blocked this request because the connected account is missing a permission "+ "required to read your ads data. Please reconnect the Meta Ads integration and grant "+ "all requested permissions."+ )+@pytest.mark.parametrize("body,expected",[