: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(google_ads): default report tables to segments.date incremental field (#90800)
Tom Owers494e3e7d7e17
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/google_ads.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/google_ads.pyindex d1d485886fa9..efc52eb5306e 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/google_ads.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/google_ads.py@@ -608,7 +608,12 @@ def google_ads_source(# incremental pipeline persists a cursor between runs, and the bounded windowed drain below is# only sound when it does.pipeline_is_incremental = should_use_incremental_field- if table.requires_filter and not should_use_incremental_field:+ # Report tables can only ever be windowed by segments.date, so force it here — both when a+ # full-refresh schema reaches the incremental path, and when a schema flagged incremental+ # arrives without an incremental field (a config that would otherwise crash the drain below).+ if table.requires_filter and (+ not should_use_incremental_field or incremental_field is None or incremental_field_type is None+ ):should_use_incremental_field = Trueincremental_field = "segments.date"incremental_field_type = IncrementalFieldType.Datediff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.pyindex 344d6402423b..83d29db618fa 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/google_ads/tests/test_google_ads_source.py@@ -587,6 +587,20 @@ def _single_row_table() -> GoogleAdsTable:)+def _stats_table() -> GoogleAdsTable:+ # A report table (requires_filter=True) whose only incremental field is ever segments.date.+ return GoogleAdsTable(+ name="campaign_stats",+ alias="campaign_stats",+ columns=[_string_column("campaign.id"), _string_column("segments.date")],+ parents=None,+ requires_filter=True,+ primary_key=["campaign.id", "segments.date"],+ should_sync_default=True,+ description=None,+ )++def _single_page() -> SimpleNamespace:return SimpleNamespace(field_mask=SimpleNamespace(paths=["campaign.name"]),@@ -1847,6 +1861,37 @@ class TestVersionDeclaration:assert GoogleAdsSource().resolve_api_version(pin) == expected+class TestReportTableMissingIncrementalField:+ def test_incremental_report_table_without_incremental_field_defaults_to_segments_date(self):+ # A report table's schema can arrive flagged incremental but with no incremental field+ # (a config inconsistency). Its only valid field is always segments.date, so the sync must+ # default to it and run rather than crashing with "incremental_field ... can't be None".+ table = _stats_table()+ assert table.alias is not None+ config = GoogleAdsSourceConfig(customer_id="1234567890", google_ads_integration_id=1)+ with (+ mock.patch(f"{_GOOGLE_ADS_MODULE}.get_schemas", return_value={table.alias: table}),+ mock.patch(f"{_GOOGLE_ADS_MODULE}.google_ads_client", return_value=mock.Mock()),+ mock.patch(f"{_GOOGLE_ADS_MODULE}._search_as_arrow_tables", return_value=iter([])) as search,+ ):+ response = google_ads_source(+ config,+ table.alias,+ team_id=1,+ resumable_source_manager=mock.Mock(),+ api_version="v25",+ should_use_incremental_field=True,+ incremental_field=None,+ incremental_field_type=None,+ db_incremental_field_last_value=dt.date.today(),+ )+ list(typing.cast(collections.abc.Iterable, response.items()))++ # The windowed drain ran (no crash) and queried on the defaulted segments.date field.+ assert search.call_count >= 1+ assert "segments.date" in search.call_args_list[0].args[2]++class TestApiVersionDispatch:@pytest.mark.parametrize("api_version", ["v23", "v24", "v25"])def test_search_service_built_for_resolved_version(self, api_version):