: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(postgres): treat jsonb_each on non-object as non-retryable (#63680)
Tom Owers1f8f98547563
diff --git a/posthog/temporal/data_imports/sources/postgres/source.py b/posthog/temporal/data_imports/sources/postgres/source.pyindex 2099b5309a37..1952b8d0fcb5 100644--- a/posthog/temporal/data_imports/sources/postgres/source.py+++ b/posthog/temporal/data_imports/sources/postgres/source.py@@ -280,6 +280,13 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa'(PostgreSQL reported "has not been populated"). Run REFRESH MATERIALIZED VIEW on it in '"your database so it contains data, then re-enable the sync."),+ # Raised by Postgres while reading a view/materialized view whose own definition calls+ # `jsonb_each()` (or `jsonb_each_text()`) on a jsonb value that isn't an object for some+ # rows (a JSON array, scalar, or `'null'`). We only ever run `SELECT ... FROM <relation>`;+ # the function lives in the customer's view definition. The failure is deterministic+ # against the source data, so retrying re-evaluates the same view and hits the same row.+ "cannot call jsonb_each on a non-object": "A view you're syncing calls jsonb_each() on a JSON value that isn't an object for at least one row, so Postgres can't evaluate the view and we can't read it. Guard the call in your view definition (for example only call jsonb_each() when jsonb_typeof(col) = 'object'), or remove that view from the sync.",+ "cannot call jsonb_each_text on a non-object": "A view you're syncing calls jsonb_each_text() on a JSON value that isn't an object for at least one row, so Postgres can't evaluate the view and we can't read it. Guard the call in your view definition (for example only call jsonb_each_text() when jsonb_typeof(col) = 'object'), or remove that view from the sync.",}def reconcile_schema_metadata(diff --git a/posthog/temporal/data_imports/sources/postgres/test_postgres.py b/posthog/temporal/data_imports/sources/postgres/test_postgres.pyindex 2140dd13c3e0..4b6bee3f7256 100644--- a/posthog/temporal/data_imports/sources/postgres/test_postgres.py+++ b/posthog/temporal/data_imports/sources/postgres/test_postgres.py@@ -341,6 +341,20 @@ class TestPostgresSourceNonRetryableErrors:assert friendly, "Unpopulated materialized view error should surface an actionable message"assert "REFRESH MATERIALIZED VIEW" in friendly[0]+ @pytest.mark.parametrize(+ "error_msg",+ [+ "cannot call jsonb_each on a non-object",+ "InvalidParameterValue: cannot call jsonb_each on a non-object",+ "cannot call jsonb_each_text on a non-object",+ "InvalidParameterValue: cannot call jsonb_each_text on a non-object",+ ],+ )+ def test_jsonb_each_on_non_object_is_non_retryable(self, source, error_msg):+ non_retryable = source.get_non_retryable_errors()+ is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())+ assert is_non_retryable, f"jsonb_each on non-object error should be non-retryable: {error_msg}"+@pytest.mark.parametrize("error_msg",[