: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(data-imports): strip NUL bytes from warehouse column statistics (#108038)
Tom Owers52a47e39bb03
diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/compute_table_statistics.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/compute_table_statistics.pyindex d2a1d22b61b6..b29ab88eb529 100644--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/compute_table_statistics.py+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/compute_table_statistics.py@@ -160,8 +160,11 @@ def _aggregate_add_action_stats(add_actions: Any, columns: dict[str, Any]) -> tumins = [v for v in data.get(min_key, []) if v is not None] if min_key in data else []maxs = [v for v in data.get(max_key, []) if v is not None] if max_key in data else []- min_value = str(min(mins)) if mins else None- max_value = str(max(maxs)) if maxs else None+ # A source string column can carry a NUL (0x00) byte; min_value/max_value land in a Postgres+ # text column, which rejects it outright. Stripping it is consistent with treating these+ # bounds as approximate (delta-rs already truncates long strings here).+ min_value = str(min(mins)).replace("\x00", "") if mins else None+ max_value = str(max(maxs)).replace("\x00", "") if maxs else Nonehas_min_max = bool(mins or maxs)result[name] = _ColumnStat(diff --git a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_compute_table_statistics.py b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_compute_table_statistics.pyindex 6b204832ba03..fc09e6fa74c8 100644--- a/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_compute_table_statistics.py+++ b/products/warehouse_sources/backend/temporal/data_imports/workflow_activities/tests/test_compute_table_statistics.py@@ -123,6 +123,10 @@ class TestAggregateAddActionStats:(3, 9, "3", "9"),(Decimal("1.50"), Decimal("9.99"), "1.50", "9.99"),(dt.date(2024, 1, 1), dt.date(2025, 6, 25), "2024-01-01", "2025-06-25"),+ # A source string column can carry a NUL byte; min_value/max_value land in a Postgres+ # text column, which rejects it outright (DataError: "PostgreSQL text fields cannot+ # contain NUL (0x00) bytes"). It must be stripped here, before the DB write.+ ("ab\x00c", "z\x00", "abc", "z"),],)def test_min_max_coerced_to_string(self, min_val, max_val, expected_min, expected_max) -> None: