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-imports): explain a sync whose rows are not objects (#98004)

Tom Owers4589de4ff94a
diff --git a/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py b/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py
index 0347d272aae5..060649d24198 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/external_data_job.py
@@ -185,6 +185,15 @@ Any_Source_Errors: dict[str, str | None] = {
"clients reject, such as an underscore. Fix the endpoint URL in your object storage settings, "
"then re-enable the sync."
),
+ # Raised in shared pipeline code (`table_from_py_list` → `_process_batch`) when a batch carries
+ # rows that aren't objects, such as a REST resource whose selected response field holds arrays or
+ # scalars. Keyless rows carry no column names to build a table from, and the same shape comes back
+ # on every retry. Keep in step with `NON_MAPPING_ROW_ERROR` in arrow_utils.
+ "Rows from this table are not JSON objects": (
+ "This table's rows aren't objects with named fields, so PostHog has no columns to import. "
+ "If the source lets you choose which part of the response to read, point it at a list of "
+ "objects, then re-enable the sync."
+ ),
}
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 7bb2ce546ed5..3af10de2dcc7 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
@@ -5,7 +5,7 @@ import math
import uuid
import decimal
import datetime
-from collections.abc import Callable, Collection, Iterable, Iterator, Sequence
+from collections.abc import Callable, Collection, Iterable, Iterator, Mapping, Sequence
from functools import _make_key, wraps
from ipaddress import IPv4Address, IPv6Address
from typing import TYPE_CHECKING, Any, Literal, Optional, cast
@@ -80,6 +80,26 @@ class MissingPrimaryKeysException(Exception):
super().__init__(message)
+# Matched as a substring by the shared non-retryable classification (`Any_Source_Errors`), so the
+# schema is paused with guidance instead of retrying rows whose shape cannot change. Keep the
+# wording in step with that entry.
+NON_MAPPING_ROW_ERROR = "Rows from this table are not JSON objects"
+
+
+class NonMappingRowError(Exception):
+ """A batch carries a row that isn't a key/value object, so there are no column names to build a
+ table from.
+
+ Usually a REST resource whose selected response field holds arrays or scalars instead of
+ objects, for example a reporting endpoint that returns bare row arrays and its column names
+ separately. The same shape comes back on every retry until the source config selects objects.
+ The message carries only the row's type, because row contents can hold customer data.
+ """
+
+ def __init__(self, row_type: str) -> None:
+ super().__init__(f"{NON_MAPPING_ROW_ERROR} (a row arrived as {row_type})")
+
+
class QueryTimeoutException(Exception):
pass
@@ -1337,12 +1357,21 @@ def _serialize_dict_columns(table_data: list[dict]) -> tuple[list[dict], set[str
def _process_batch(
- table_data: list[dict],
+ # Not `list[dict]`: a source can hand the pipeline rows that aren't objects, which the guard
+ # below rejects.
+ table_data: list[Any],
schema: Optional[pa.Schema] = None,
*,
primary_keys: Optional[Sequence[str]] = None,
binary_reporter: Optional[BinaryColumnReporter] = None,
) -> pa.Table:
+ # Every step below reads a row as a mapping, so without this check a keyless row fails deep in
+ # the conversion with a bare `'list' object has no attribute 'items'`, which names neither the
+ # cause nor a fix.
+ for row in table_data:
+ if not isinstance(row, Mapping):
+ raise NonMappingRowError(type(row).__name__)
+
table_data, serialized_dict_columns = _serialize_dict_columns(table_data)
# Support both given schemas and inferred schemas
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 44711705b6ac..0a465e0ec03f 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
@@ -21,6 +21,7 @@ from products.warehouse_sources.backend.temporal.data_imports.external_data_job
from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.arrow_utils import (
BillingLimitsWillBeReachedException,
BinaryColumnReporter,
+ NonMappingRowError,
SchemaColumnTypeChangedException,
_get_max_decimal_type,
_to_list_array,
@@ -256,6 +257,31 @@ def test_table_from_py_list_with_lists():
)
+ "rows,row_type",
+ [
+ # A reporting endpoint whose selected field holds arrays, with column names returned
+ # separately, so every row reaches the pipeline without keys.
+ ([["first", 12], ["second", 34]], "list"),
+ # A selected field holding bare scalars.
+ (["first", "second"], "str"),
+ # Only a later row is keyless, so the check can't stop at the first row.
+ ([{"id": "first"}, ["second", 34]], "list"),
+ ],
+)
+def test_table_from_py_list_rejects_non_mapping_rows(rows, row_type):
+ with pytest.raises(NonMappingRowError) as exc_info:
+ table_from_py_list(rows)
+
+ message = str(exc_info.value)
+ assert row_type in message
+ # Row contents can hold customer data, so only the type is named
+ assert "first" not in message
+ # The message must stay matched by an Any_Source_Errors entry so the schema is paused with
+ # guidance instead of retrying rows whose shape can't change, on every source.
+ assert [key for key in Any_Source_Errors if key in message]
+
+
def test_table_from_py_list_with_nan():
table = table_from_py_list([{"column": 1.0}, {"column": float("NaN")}])