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(data-imports): skip incremental-field lookup for xmin/CDC schemas (#74958)

Tom Owersd8afb686f03b
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/load.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/load.py
index 53f1b2ef2f1f..319c9753fb4b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/load.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/load.py
@@ -66,7 +66,10 @@ class IncrementalFieldMissingFromDataError(Exception):
def get_incremental_field_value(
schema: ExternalDataSchema | None, table: pa.Table, aggregate: Literal["max"] | Literal["min"] = "max"
) -> Any:
- if schema is None or schema.sync_type == ExternalDataSchema.SyncType.FULL_REFRESH:
+ # CDC and xmin schemas track their own cursor (CDC log position, xmin ceiling) outside of
+ # sync_type_config["incremental_field"] — that key can be a stale leftover from a prior
+ # incremental config and must not be looked up for these sync types.
+ if schema is None or not schema.should_use_incremental_field:
return None
incremental_field_name: str | None = schema.sync_type_config.get("incremental_field")
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_load.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_load.py
index 8c465534e2cb..fa751109a537 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_load.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_load.py
@@ -218,11 +218,16 @@ class TestRunPostLoadDeltaMaintenance:
class TestGetIncrementalFieldValue:
- def _schema(self, incremental_field: str) -> MagicMock:
+ def _schema(self, incremental_field: str, sync_type: str = ExternalDataSchema.SyncType.INCREMENTAL) -> MagicMock:
schema = MagicMock()
- schema.sync_type = ExternalDataSchema.SyncType.INCREMENTAL
+ schema.sync_type = sync_type
schema.sync_type_config = {"incremental_field": incremental_field, "incremental_field_type": "integer"}
schema.incremental_field_type = "integer"
+ schema.should_use_incremental_field = sync_type in (
+ ExternalDataSchema.SyncType.INCREMENTAL,
+ ExternalDataSchema.SyncType.APPEND,
+ ExternalDataSchema.SyncType.WEBHOOK,
+ )
return schema
def test_returns_max_of_configured_column(self):
@@ -243,3 +248,19 @@ class TestGetIncrementalFieldValue:
assert "created" in message # available columns are listed for self-service fixing
matching_keys = [key for key in Any_Source_Errors if key in message]
assert matching_keys, "exception message must stay matched by an Any_Source_Errors entry"
+
+ @parameterized.expand(
+ [
+ ("xmin", ExternalDataSchema.SyncType.XMIN),
+ ("cdc", ExternalDataSchema.SyncType.CDC),
+ ]
+ )
+ def test_stale_incremental_field_ignored_for_self_tracking_sync_types(self, _name: str, sync_type: str):
+ # xmin/cdc track their cursor outside sync_type_config (xmin_ceiling, cdc_last_log_position).
+ # A schema switched from incremental to xmin/cdc keeps the old incremental_field key around,
+ # which used to raise IncrementalFieldMissingFromDataError even though this sync type never
+ # reads that column.
+ table = pa.table({"id": ["a"], "created": [10]})
+ schema = self._schema("updated_at", sync_type=sync_type)
+
+ assert get_incremental_field_value(schema, table) is None