: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
feat(warehouse_sources): support Meta Ads API version v26.0 (#80086)
Tom Owers21ba7285e30e
diff --git a/.agents/skills/warehouse-source-new-version/SKILL.md b/.agents/skills/warehouse-source-new-version/SKILL.mdindex 62c17f389a52..5cec408d1a23 100644--- a/.agents/skills/warehouse-source-new-version/SKILL.md+++ b/.agents/skills/warehouse-source-new-version/SKILL.md@@ -89,6 +89,7 @@ Add it when any of these hold:- A version bump can change the auth scheme, not just the wire format. Then the source config needs both credential shapes as optional fields, auth construction dispatches on the resolved version, and `validate_credentials` enforces the pair that version needs — form-level `required` can't express "depends on the pin".- When the vendor renames a collection between versions, keep the schema/table name set identical across versions and put the rename in a per-version path on the endpoint config — otherwise discovery diffs orphan the table on repin.- When the new version has no equivalent for an old endpoint (a dropped collection, not a rename), keep that table only on the versions that serve it and let the table set differ by version — never map it to a guessed path just to keep the sets equal, since docs are the sole source of truth and an unverified path makes a new source surface a table that 404s at sync time.+- A source with no dispatch may currently read its version from a constant on a shared model (e.g. the OAuth `Integration` model) that also drives version-independent flows like OAuth token minting. Repoint only the sync request path onto the resolved pin; leave that constant, since bumping it changes those other flows' version with a blast radius beyond this source.## Self-improvementdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/meta_ads.py b/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/meta_ads.pyindex d7386fdd1c18..36e2313e30fe 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/meta_ads.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/meta_ads/meta_ads.py@@ -38,6 +38,13 @@ from products.warehouse_sources.backend.types import IncrementalFieldTypelogger = structlog.get_logger(__name__)+# Graph API versions this source can sync against, as opaque vendor labels copied verbatim+# from Meta's changelog — never parsed or ordered. The resolved source pin is threaded into+# every request URL's `{API_VERSION}` segment by `meta_ads_source`.+# https://developers.facebook.com/docs/graph-api/changelog+META_ADS_API_VERSION_V25 = "v25.0"+META_ADS_API_VERSION_V26 = "v26.0"+# Meta Ads API only supports data from the last 3 years. Meta's insights endpoints# reject a `time_range` whose start is beyond ~37 months from today with error code# 3018 ("The start date of the time range cannot be beyond 37 months from the current@@ -892,12 +899,13 @@ def meta_ads_source(config: MetaAdsSourceConfig,team_id: int,resumable_source_manager: ResumableSourceManager[MetaAdsResumeConfig],+ api_version: str,should_use_incremental_field: bool = False,db_incremental_field_last_value: typing.Any = None,incremental_field: str | None = None,incremental_field_type: IncrementalFieldType | None = None,) -> SourceResponse:- """A data warehouse Meta Ads source."""+ """A data warehouse Meta Ads source. ``api_version`` is the source instance's resolved pin."""name = NamingConvention.normalize_identifier(resource_name)schema = get_schemas()[resource_name]@@ -944,9 +952,7 @@ def meta_ads_source("until": today.strftime("%Y-%m-%d"),}- formatted_url = schema.url.format(- API_VERSION=MetaAdsIntegration.api_version, account_id=_clean_account_id(config.account_id)- )+ formatted_url = schema.url.format(API_VERSION=api_version, account_id=_clean_account_id(config.account_id))if schema.single_object:yield from _fetch_single_object(formatted_url, {"fields": ",".join(schema.field_names)}, access_token)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 f1bbce30a8a6..9086ecd0a078 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@@ -40,6 +40,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.generated_MetaAdsSourceConfig,)from products.warehouse_sources.backend.temporal.data_imports.sources.meta_ads.meta_ads import (+ META_ADS_API_VERSION_V25,+ META_ADS_API_VERSION_V26,META_AUTH_ERROR_MESSAGE,META_RATE_LIMIT_ERROR_MESSAGE,SHRINK_EXHAUSTED_ERROR_MESSAGE,@@ -82,8 +84,8 @@ def _status_badges(account: dict) -> tuple[str, ...]:class MetaAdsSource(ResumableSource[MetaAdsSourceConfig, MetaAdsResumeConfig], OAuthMixin):lists_tables_without_credentials = True # static endpoint catalog — safe for public docs- supported_versions = ("v25.0",)- default_version = "v25.0"+ supported_versions = (META_ADS_API_VERSION_V25, META_ADS_API_VERSION_V26)+ default_version = META_ADS_API_VERSION_V26api_docs_url = "https://developers.facebook.com/docs/graph-api/changelog"@property@@ -182,6 +184,7 @@ class MetaAdsSource(ResumableSource[MetaAdsSourceConfig, MetaAdsResumeConfig], Oconfig=config,team_id=inputs.team_id,resumable_source_manager=resumable_source_manager,+ api_version=self.resolve_api_version(inputs.api_version),should_use_incremental_field=inputs.should_use_incremental_field,incremental_field=inputs.incremental_field if inputs.should_use_incremental_field else None,incremental_field_type=inputs.incremental_field_type if inputs.should_use_incremental_field else None,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.pyindex bb354814e751..ba5f6642a66f 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@@ -25,6 +25,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.meta_ads.mAD_ACCOUNT_LISTING_TIMEOUT_SECONDS,MALFORMED_JSON_MAX_ATTEMPTS,MAX_AD_ACCOUNT_PAGES,+ META_ADS_API_VERSION_V25,+ META_ADS_API_VERSION_V26,META_ADS_MAX_HISTORY_DAYS,META_AUTH_ERROR_MESSAGE,META_TRANSIENT_ERROR_MAX_ATTEMPTS,@@ -1427,6 +1429,7 @@ class TestTimeRangeClamping:config=config,team_id=1,resumable_source_manager=_build_manager(),+ api_version=META_ADS_API_VERSION_V26,**source_kwargs,)list(cast(Any, response.items()))@@ -1774,6 +1777,7 @@ class TestBreakdownStatsRequests:config=config or _source_config(),team_id=1,resumable_source_manager=_build_manager(),+ api_version=META_ADS_API_VERSION_V26,)list(cast(Any, response.items()))return captured@@ -1845,6 +1849,7 @@ class TestSingleObjectEndpoint:config=_source_config(),team_id=1,resumable_source_manager=_build_manager(),+ api_version=META_ADS_API_VERSION_V26,)return list(cast(Any, source.items()))@@ -1869,3 +1874,41 @@ class TestSingleObjectEndpoint:field_names = get_meta_ads_schemas()[MetaAdsResource.AdAccount].field_namesassert "business" not in field_namesassert {"business_name", "business_country_code"} <= set(field_names)+++class TestApiVersionDispatch:+ """The resolved source pin must reach the request URL — otherwise a pinned source silently+ syncs against the wrong Graph API version, the drift the pinning framework exists to prevent."""++ def _capture_url(self, monkeypatch, api_version: str) -> str:+ integration = mock.MagicMock()+ integration.access_token = "token"+ monkeypatch.setattr(meta_ads_module, "get_integration", lambda config, team_id: integration)++ captured: dict[str, str] = {}++ def fake_request(url, params, access_token, time_range, resumable_source_manager):+ captured["url"] = url+ yield from ()++ monkeypatch.setattr(meta_ads_module, "_make_paginated_api_request", fake_request)++ response = meta_ads_source(+ resource_name=MetaAdsResource.Campaigns,+ config=_source_config(),+ team_id=1,+ resumable_source_manager=_build_manager(),+ api_version=api_version,+ )+ list(cast(Any, response.items()))+ return captured["url"]++ @pytest.mark.parametrize("api_version", list(MetaAdsSource.supported_versions))+ def test_resolved_version_reaches_request_url(self, monkeypatch, api_version: str) -> None:+ assert (+ self._capture_url(monkeypatch, api_version) == f"https://graph.facebook.com/{api_version}/act_123/campaigns"+ )++ def test_new_sources_default_to_latest_while_previous_stays_supported(self) -> None:+ assert MetaAdsSource.default_version == META_ADS_API_VERSION_V26+ assert set(MetaAdsSource.supported_versions) == {META_ADS_API_VERSION_V25, META_ADS_API_VERSION_V26}