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(postgres): map UUID columns to Arrow string when absent from schema (#83925)

Tom Owers6a9a68861a11
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.py
index 2208d917db3e..938b79508734 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
@@ -864,6 +864,11 @@ def _python_type_to_pyarrow_type(type_: type, value: Any):
if issubclass(type_, datetime.time) and isinstance(value, datetime.time):
return pa.time64("us")
+ # UUID values are stringified later in `_process_batch`; declare the field as string here so a
+ # UUID column absent from the provided schema doesn't crash while its field is being appended.
+ if issubclass(type_, uuid.UUID):
+ return pa.string()
+
raise ValueError(f"Python type {type_} has no pyarrow mapping")
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.py
index 280e11f9d367..3a96c1a45e4d 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
@@ -60,6 +60,17 @@ def test_table_from_py_list_uuid():
)
+def test_table_from_py_list_schema_missing_uuid_column():
+ # A UUID column present in the batch but absent from the provided schema has its Arrow field
+ # inferred by `_python_type_to_pyarrow_type`, which must map UUID to string rather than raising.
+ uuid_ = uuid.uuid4()
+ schema = pa.schema(cast(Any, [pa.field("id", pa.int64())]))
+ table = table_from_py_list([{"id": 1, "uid": uuid_}], schema)
+
+ assert table.schema.field("uid").type == pa.string()
+ assert table.column("uid").to_pylist() == [str(uuid_)]
+
+
def test_table_from_py_list_inconsistent_list():
table = table_from_py_list([{"column": "hello"}, {"column": ["hi"]}])