: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): stop str+dict column fallback dropping a third mixed type (#86749)
Tom Owers1334693264d8
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/arrow_utils.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/arrow_utils.pyindex 938b79508734..f1eab656e65d 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/arrow_utils.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/arrow_utils.py@@ -1236,11 +1236,14 @@ def _process_batch(table_data: list[dict], schema: Optional[pa.Schema] = None) -if arrow_schema:arrow_schema = arrow_schema.set(field_index, arrow_schema.field(field_index).with_type(pa.string()))- # If str and dict are shared - then turn everything into a json string+ # If str and dict are shared - then turn everything into a json string. A column can also+ # carry a third type alongside them (e.g. an int, as with a free-form field that varies per+ # row) — JSON-dump anything that isn't already a string rather than only dict/list, so that+ # third type doesn't reach pa.array() unconverted and raise ArrowTypeError.if len(unique_types_in_column) > 1 and str in unique_types_in_column and dict in unique_types_in_column:json_array = pa.array([- None if s is None else _json_dumps(s) if isinstance(s, dict | list) else s+ None if s is None else s if isinstance(s, str) else _json_dumps(s)for s in _to_list_array(columnar_table_data[field_name])])diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_utils.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_utils.pyindex 76918c1c62f8..1f5d5cae77a4 100644--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_utils.py+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/core/test/test_utils.py@@ -164,10 +164,20 @@ def test_table_from_py_list_inconsistent_types_with_none():)-def test_table_from_py_list_inconsistent_types_with_str_and_dict():- table = table_from_py_list([{"column": "hello"}, {"column": {"field": 1}}])+ "rows,expected",+ [+ ([{"column": "hello"}, {"column": {"field": 1}}], ["hello", '{"field":1}']),+ # A third scalar type (e.g. int) alongside str and dict used to reach pa.array()+ # unconverted and raise "ArrowTypeError: Expected bytes, got a 'int' object" — a free-form+ # field that's sometimes a plain number is a real shape (e.g. an execution's JSON output).+ ([{"column": "hello"}, {"column": {"field": 1}}, {"column": 5}], ["hello", '{"field":1}', "5"]),+ ],+)+def test_table_from_py_list_inconsistent_types_with_str_and_dict(rows, expected):+ table = table_from_py_list(rows)- assert table.equals(pa.table({"column": ["hello", '{"field":1}']}))+ assert table.equals(pa.table({"column": expected}))assert table.schema.equals(pa.schema([