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-warehouse): show cumulative row count for xmin schemas (#65326)

Daniel RC0eff38836e59
diff --git a/posthog/temporal/data_imports/pipelines/pipeline_sync.py b/posthog/temporal/data_imports/pipelines/pipeline_sync.py
index 75fea10b928d..4cabebf55b25 100644
--- a/posthog/temporal/data_imports/pipelines/pipeline_sync.py
+++ b/posthog/temporal/data_imports/pipelines/pipeline_sync.py
@@ -176,7 +176,6 @@ async def validate_schema_and_update_table(
_schema_id = external_data_schema.id
_schema_name: str = external_data_schema.name
- incremental_or_append = external_data_schema.should_use_incremental_field
# The HogQL table name derives from the raw schema name (only lower-cased); the S3 folder is
# the snake_cased `s3_folder_name`. They differ on purpose — see `resolve_table_and_folder_names`.
@@ -206,7 +205,7 @@ async def validate_schema_and_update_table(
table_created.format = table_params["format"]
table_created.url_pattern = new_url_pattern
table_created.queryable_folder = queryable_folder
- if incremental_or_append or external_data_schema.is_cdc:
+ if external_data_schema.table_row_count_is_cumulative:
table_created.row_count = table_created.get_count()
else:
table_created.row_count = row_count
diff --git a/products/warehouse_sources/backend/models/external_data_schema.py b/products/warehouse_sources/backend/models/external_data_schema.py
index a94b56695155..c524b7ddb711 100644
--- a/products/warehouse_sources/backend/models/external_data_schema.py
+++ b/products/warehouse_sources/backend/models/external_data_schema.py
@@ -175,6 +175,13 @@ class ExternalDataSchema(ModelActivityMixin, CreatedMetaFields, UpdatedMetaField
def should_use_incremental_field(self):
return self.is_incremental or self.is_append or self.is_webhook
+ @property
+ def table_row_count_is_cumulative(self) -> bool:
+ # These sync types append/merge into the warehouse table across runs, so its true size is the
+ # full table count — not the latest run's row_count, which is only that run's delta. Full refresh
+ # replaces the whole table, so there the run's row_count already equals the table size.
+ return self.should_use_incremental_field or self.is_cdc or self.is_xmin
+
@property
def incremental_field(self) -> str | None:
if self.sync_type_config:
diff --git a/products/warehouse_sources/backend/tests/test_models.py b/products/warehouse_sources/backend/tests/test_models.py
index 0b28284a2ff7..3fab715f5cdd 100644
--- a/products/warehouse_sources/backend/tests/test_models.py
+++ b/products/warehouse_sources/backend/tests/test_models.py
@@ -221,6 +221,22 @@ def test_is_xmin(sync_type: str | None, expected: bool) -> None:
assert ExternalDataSchema(sync_type=sync_type).is_xmin is expected
+ "sync_type,expected",
+ [
+ (ExternalDataSchema.SyncType.XMIN, True),
+ (ExternalDataSchema.SyncType.INCREMENTAL, True),
+ (ExternalDataSchema.SyncType.APPEND, True),
+ (ExternalDataSchema.SyncType.WEBHOOK, True),
+ (ExternalDataSchema.SyncType.CDC, True),
+ (ExternalDataSchema.SyncType.FULL_REFRESH, False),
+ (None, False),
+ ],
+)
+def test_table_row_count_is_cumulative(sync_type: str | None, expected: bool) -> None:
+ assert ExternalDataSchema(sync_type=sync_type).table_row_count_is_cumulative is expected
+
+
@pytest.mark.parametrize(
"sync_type_config,expected",
[