: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(warehouse_sources): stop the Apple Ads campaign report filtering on campaignId (#94858)
posthog[bot]421f78ce4f80
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/settings.pyindex cd3b3e632568..5b67dc1e8ae0 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/settings.py@@ -81,7 +81,8 @@ class AppleSearchAdsEndpointConfig:requires_context: bool = True# Endpoints Apple only serves per campaign, built by fanning out over the account's# campaign ids. v5 takes the campaign in the path; the Platform API takes it as a filter,- # and additionally requires one on every report and on the keyword query.+ # and additionally requires one on the ad group and keyword reports and on the keyword+ # query.fan_out_over_campaigns: bool = False# Column the Platform API's `metadata.id` is projected onto, so a report table keeps the# primary key it had under v5.@@ -190,9 +191,8 @@ APPLE_ADS_PLATFORM_ENDPOINTS: dict[str, AppleSearchAdsEndpointConfig] = {name="campaign_report",path="/reports/apps/campaigns/query",kind="report",- # Apple requires a `campaignId` filter on every apps report, including this one, which- # v5 served for the whole organization in a single request.- fan_out_over_campaigns=True,+ # No fan-out: `campaignId` is this report's own row entity, and Apple rejects it as a+ # filter field here, so one request covers the whole ad account as it did under v5.entity_id_field="campaignId",primary_keys=["campaignId", "date"],partition_key="date",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/tests/test_apple_search_ads.py b/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/tests/test_apple_search_ads.pyindex fe968d0c92b4..38b0adc4b863 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/tests/test_apple_search_ads.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/apple_search_ads/tests/test_apple_search_ads.py@@ -445,13 +445,8 @@ class TestPlatformApiPaths:[{"field": "campaignId", "operator": "EQUALS", "value": 20}],]- def test_reports_carry_a_time_range_and_a_required_campaign_filter(self) -> None:- session = _FakeSession(- [- _entity_page([{"id": 10}], V1),- _report_page([_report_row({"id": 10}, ["2026-06-01"], V1)], V1),- ]- )+ def test_reports_carry_a_time_range(self) -> None:+ session = _FakeSession([_report_page([_report_row({"id": 10}, ["2026-06-01"], V1)], V1)])with mock.patch(TODAY_PATCH, return_value=date(2026, 6, 2)):_run(@@ -473,24 +468,40 @@ class TestPlatformApiPaths:"granularity": "DAILY",}assert body["pagination"] == {"offset": 0, "pageSize": PAGE_SIZE}- # Apple requires a campaignId filter on every apps report, including the campaign level,- # and documents the value as an array of strings.- assert body["filters"] == [{"field": "campaignId", "operator": "EQUALS", "value": ["10"]}]# Unsegmented daily rows, so no groupBy is sent.assert "groupBy" not in body- def test_the_campaign_report_fans_out_over_every_campaign(self) -> None:+ def test_the_campaign_report_reads_the_whole_ad_account_in_one_request(self) -> None:+ session = _FakeSession([_report_page([_report_row({"id": 10}, ["2026-06-01"], V1)], V1)])++ with mock.patch(TODAY_PATCH, return_value=date(2026, 6, 2)):+ batches = _run(+ "campaign_report",+ session,+ _FakeResumableManager(),+ api_version=V1,+ should_use_incremental_field=True,+ db_incremental_field_last_value=date(2026, 6, 1),+ )++ # `campaignId` is this report's own row entity, so Apple rejects it as a filter field+ # with `INVALID_FIELD_ATTRIBUTE`: no campaign list, and no filters on the request.+ assert [call["url"] for call in session.api_calls] == [f"{BASE_URL[V1]}/reports/apps/campaigns/query"]+ assert "filters" not in session.api_calls[0]["json"]+ assert [row["campaignId"] for batch in batches for row in batch] == [10]++ def test_sub_campaign_reports_still_carry_the_campaign_filter(self) -> None:session = _FakeSession([_entity_page([{"id": 20}, {"id": 10}], V1),- _report_page([_report_row({"id": 10}, ["2026-06-01"], V1)], V1),- _report_page([_report_row({"id": 20}, ["2026-06-01"], V1)], V1),+ _report_page([_report_row({"id": 1, "campaignId": 10}, ["2026-06-01"], V1)], V1),+ _report_page([_report_row({"id": 2, "campaignId": 20}, ["2026-06-01"], V1)], V1),])with mock.patch(TODAY_PATCH, return_value=date(2026, 6, 2)):- batches = _run(- "campaign_report",+ _run(+ "ad_group_report",session,_FakeResumableManager(),api_version=V1,@@ -498,7 +509,13 @@ class TestPlatformApiPaths:db_incremental_field_last_value=date(2026, 6, 1),)- assert [row["campaignId"] for batch in batches for row in batch] == [10, 20]+ report_calls = [call for call in session.api_calls if "/reports/" in call["url"]]+ # Apple documents the report filter's value as an array of strings, and the ids are+ # visited in a stable ascending order rather than response order.+ assert [call["json"]["filters"] for call in report_calls] == [+ [{"field": "campaignId", "operator": "EQUALS", "value": ["10"]}],+ [{"field": "campaignId", "operator": "EQUALS", "value": ["20"]}],+ ]def test_acl_rows_become_one_row_per_ad_account(self) -> None:session = _FakeSession(@@ -801,9 +818,6 @@ class TestReportSync:_report_page(full_page, api_version),_report_page([_report_row({"campaignId": 9999}, ["2026-06-01"], api_version)], api_version),]- if api_version == V1:- # The Platform API needs a campaign filter on this report, so the list comes first.- responses.insert(0, _entity_page([{"id": 1}], V1))session = _FakeSession(responses)manager = _FakeResumableManager()