Skip to content

: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.

fix(warehouse): drop business_management-gated fields from Meta Ads ad_account (#80824)

jake sciottoa806df9eeed2
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/schemas.py b/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/schemas.py
index 92e0f6efdd34..1ff74a97b61b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/schemas.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/schemas.py
@@ -423,16 +423,14 @@ RESOURCE_SCHEMAS: dict[MetaAdsResource, dict[str, Any]] = {
"created_time",
"business_country_code",
"business_name",
- # No `business`: reading it needs the `business_management` scope, which the Meta
- # OAuth consent doesn't request (`ads_read` only) — see `AD_ACCOUNT_FIELDS` in
- # meta_ads.py, which excludes it from the account-listing request for the same reason.
- # Meta 400s the whole request when it's asked for, failing this table's sync outright.
- "funding_source_details",
"disable_reason",
- "is_prepay_account",
- "tos_accepted",
"capabilities",
- "owner",
+ # No `business`, `owner`, `funding_source_details`, `is_prepay_account`, or
+ # `tos_accepted`: each needs the `business_management` scope, which the Meta OAuth
+ # consent doesn't request (`ads_read` only) — see `AD_ACCOUNT_FIELDS` in meta_ads.py,
+ # which excludes `business` from the account-listing request for the same reason.
+ # Meta rejects the whole field set when any one of them is asked for without that
+ # scope, so a single one of these sneaking back in fails this table's sync outright.
],
"single_object": True,
},
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.py
index 9086ecd0a078..03d7413554d0 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
@@ -131,6 +131,17 @@ 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 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` (see
+ # `AD_ACCOUNT_FIELDS` in meta_ads.py). Only the account owner granting
+ # `business_management`, or PostHog dropping the field that needs it, fixes this.
+ "Requires business_management permission": (
+ "Meta rejected part of this request because it needs the business_management "
+ "permission, which this integration does not request and cannot request without "
+ "widening OAuth consent for every customer. Re-authorizing will not fix this — "
+ "contact PostHog support if this table keeps failing."
+ ),
# Meta returns this 500 when the requested query is too large for their backend to
# service. Both pagination paths adapt to it (stats chunks shrink 30 → 7 → 1 day, and
# both paths shrink the per-page limit 500 → 100 → 50); if it still escapes after those
diff --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.py
index a7b3046ca72d..caac9759b112 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 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}}',
# 500 when Meta's backend refuses to service the query even after adaptive
# chunking has shrunk the window to its smallest size.
'Meta API request failed: 500 - {"error":{"code":1,"message":"Please reduce the amount of data you\'re asking for, then retry your request"}}',
@@ -1952,6 +1954,15 @@ class TestSingleObjectEndpoint:
assert "business" not in field_names
assert {"business_name", "business_country_code"} <= set(field_names)
+ def test_field_list_omits_fields_gated_behind_business_management(self) -> None:
+ # These four live in the same business_management-gated family as `business` above, but
+ # each was pruned only from `AD_ACCOUNT_FIELDS` in meta_ads.py, not from this list — Meta
+ # rejects the whole field set when any one field needs a scope beyond `ads_read`, so any
+ # one of them sneaking back in fails every sync of this table, not just that field.
+ gated_fields = {"owner", "funding_source_details", "is_prepay_account", "tos_accepted"}
+ field_names = get_meta_ads_schemas()[MetaAdsResource.AdAccount].field_names
+ assert gated_fields.isdisjoint(field_names)
+
class TestApiVersionDispatch:
"""The resolved source pin must reach the request URL — otherwise a pinned source silently