: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): promote numeric types when unifying v3 batch schemas (#78432)
Tom Owersec2b4f05ce6f
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/s3/test_writer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/s3/test_writer.pyindex 04a12691c53c..a420c89f5d25 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/s3/test_writer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/s3/test_writer.py@@ -1,5 +1,6 @@import jsonimport errno+from datetime import UTC, datetimeimport pytestfrom unittest.mock import MagicMock, patch@@ -7,6 +8,7 @@ from unittest.mock import MagicMock, patchimport pyarrow as pafrom products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.s3.writer import (+ S3BatchWriter,_write_parquet_to_s3,build_schema_dict,)@@ -75,3 +77,32 @@ class TestBuildSchemaDict:schema = pa.schema([pa.field("id", pa.int64())])assert build_schema_dict(schema)["fields"][0]["metadata"] is None+++class TestSchemaAccumulation:+ @patch(+ "products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.s3.writer._write_parquet_to_s3"+ )+ @patch("products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.s3.writer.ensure_bucket")+ @patch("products.warehouse_sources.backend.temporal.data_imports.pipelines.pipeline_v3.s3.writer.get_s3_client")+ def test_accumulated_schema_promotes_int_to_double_across_batches(+ self, mock_get_s3_client, _mock_ensure_bucket, _mock_write+ ) -> None:+ # Two batches of the same column can infer different numeric types within one run (whole+ # values -> int64, later fractional values -> double). Unifying them must widen to double+ # rather than raising ArrowTypeError, which would crash the whole extraction.+ mock_get_s3_client.return_value.info.return_value = {"Size": 1}++ job = MagicMock()+ job.team_id = 1+ job.created_at = datetime(2026, 8, 5, tzinfo=UTC)+ job.workflow_run_id = "run-1"++ writer = S3BatchWriter(MagicMock(), job, schema_id="schema-1", run_uuid="run-1")++ writer.write_batch(pa.table({"consumed_quantity": pa.array([1, 2], type=pa.int64())}), 0)+ writer.write_batch(pa.table({"consumed_quantity": pa.array([1.5, 2.5], type=pa.float64())}), 1)++ schema = writer.get_schema()+ assert schema is not None+ assert schema.field("consumed_quantity").type == pa.float64()diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/s3/writer.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/s3/writer.pyindex b7acb4ec80e5..2f3cabb4ac8a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/s3/writer.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline_v3/s3/writer.py@@ -142,7 +142,10 @@ class S3BatchWriter:if self._schema is None:self._schema = pa_table.schemaelse:- self._schema = pa.unify_schemas([self._schema, pa_table.schema])+ # Batches infer their own types, so one run's column can land int64 in an early batch and+ # double in a later one (whole vs fractional values). Permissive promotion widens to the+ # common type instead of raising ArrowTypeError; the default only unifies identical types.+ self._schema = pa.unify_schemas([self._schema, pa_table.schema], promote_options="permissive")self._logger.debug(f"Batch {batch_index} written successfully",