: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 retrying unsupported interval date_trunc units on postgres sources (#74749)
Tom Owersdf8dff84b2f6
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.pyindex dd87017f8e4c..83f78f657ae5 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/source.py@@ -671,6 +671,21 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa# 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.",+ # A selected relation's own definition calls date_trunc()/extract() with a unit+ # PostgreSQL doesn't support for the interval type (SQLSTATE 0A000) — e.g.+ # `date_trunc('week', some_interval_column)`, since week truncation is only defined+ # for timestamp/timestamptz, not interval. We only ever run `SELECT ... FROM+ # <relation>`; the expression lives in the customer's own generated column or view+ # definition, so it's deterministic against the schema and retrying re-evaluates the+ # same relation into the same wall.+ "not supported for type interval": (+ "A table or view you're syncing has a computed column or definition that calls "+ "date_trunc() or extract() with a unit PostgreSQL doesn't support for interval "+ 'values (PostgreSQL reported "not supported for type interval") — for example '+ "truncating to a week on an interval column, which is only supported on "+ "timestamps. Update that column's definition to use a supported unit, or remove "+ "it from the sync, then re-enable the sync."+ ),# A selected relation's own definition writes to the database while we read it — a view or# trigger that calls a function which runs REFRESH MATERIALIZED VIEW (or INSERT/UPDATE/DELETE).# We read inside a read-only transaction and never write to the source, so Postgres rejectsdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.pyindex 00135c1cb677..4313fae5129b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postgres/test_postgres.py@@ -992,6 +992,27 @@ class TestPostgresSourceNonRetryableErrors: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",+ [+ # Raw psycopg message (what the activity-level check sees via str(e)).+ 'unit "week" not supported for type interval',+ # Temporal-wrapped message (what the workflow-level check sees) — carries the class name.+ 'FeatureNotSupported: unit "week" not supported for type interval',+ ],+ )+ def test_interval_unit_not_supported_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"Unsupported interval-unit error should be non-retryable: {error_msg}"++ def test_interval_unit_not_supported_returns_friendly_message(self, source):+ non_retryable = source.get_non_retryable_errors()+ error_msg = 'unit "week" not supported for type interval'+ friendly = [reason for pattern, reason in non_retryable.items() if pattern in error_msg and reason]+ assert friendly, "Unsupported interval-unit error should surface an actionable message"+ assert "interval" in friendly[0]+@pytest.mark.parametrize("error_msg",[