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(google_ads): always query report tables on segments.date (#112741)

Tom Owersd51b157483b2
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.py
index b97805dd399e..fc6866c083ba 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
@@ -612,12 +612,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
- # 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
- ):
+ # Report tables can only ever be windowed by segments.date, so force it here unconditionally —
+ # a full-refresh schema reaching the incremental path, a schema flagged incremental but missing
+ # an incremental field, and a stored config carrying a stale value (e.g. the underscore-joined
+ # synced column name `segments_date` instead of the queryable `segments.date`) all land on the
+ # same, only valid field instead of sending an invalid one to Google.
+ if table.requires_filter:
should_use_incremental_field = True
incremental_field = "segments.date"
incremental_field_type = IncrementalFieldType.Date
diff --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.py
index 2dd96a0f83bc..924f6072aafe 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
@@ -1886,10 +1886,23 @@ class TestVersionDeclaration:
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".
+ @pytest.mark.parametrize(
+ "incremental_field,incremental_field_type",
+ [
+ pytest.param(None, None, id="missing"),
+ # A stored config can also carry the underscore-joined synced column name
+ # (`segments_date`) instead of the queryable `segments.date` — e.g. a stale value from
+ # before a schema was reconciled. Google rejects that field name outright, so it must be
+ # corrected the same way a missing field is.
+ pytest.param("segments_date", IncrementalFieldType.Date, id="stale_underscore_value"),
+ ],
+ )
+ def test_incremental_report_table_with_bad_incremental_field_defaults_to_segments_date(
+ self, incremental_field, incremental_field_type
+ ):
+ # A report table's schema can arrive flagged incremental but with no, or an invalid,
+ # incremental field. Its only valid field is always segments.date, so the sync must use it
+ # rather than crashing or sending Google a field it will reject.
table = _stats_table()
assert table.alias is not None
config = GoogleAdsSourceConfig(customer_id="1234567890", google_ads_integration_id=1)
@@ -1905,15 +1918,16 @@ class TestReportTableMissingIncrementalField:
resumable_source_manager=mock.Mock(),
api_version="v25",
should_use_incremental_field=True,
- incremental_field=None,
- incremental_field_type=None,
+ incremental_field=incremental_field,
+ incremental_field_type=incremental_field_type,
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.
+ # The windowed drain ran (no crash) and queried on the corrected segments.date field.
assert search.call_count >= 1
assert "segments.date" in search.call_args_list[0].args[2]
+ assert "segments_date" not in search.call_args_list[0].args[2]
class TestUnknownResource: