: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(warehouse-sources): stop retrying postgres foreign-table timestamp mismatches (#99443)
Tom Owers03ee21a994d2
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 0c464d02a6f2..94734366ba6b 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@@ -1014,6 +1014,23 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa"column's declared length to match the remote server, or remove the foreign table ""from the sync, then re-enable the sync."),+ # A selected relation is a foreign table (postgres_fdw, or a wrapper such as Supabase's+ # "Wrappers" extension) whose locally-declared column is a timestamp/date type, but the+ # remote server returns a value that doesn't parse as one (SQLSTATE 22007). Postgres+ # enforces type validity at write time on ordinary tables, so this can only surface via a+ # foreign table's separately-declared type reading data the remote side never validated+ # against it — for example a text "\N" NULL marker left over from a text-format export+ # that the remote side or wrapper didn't translate to a real NULL. The mismatch lives on+ # the customer's side and is deterministic, so retrying re-reads into the same row every+ # time. Match the stable message and exclude the volatile offending value.+ "invalid input syntax for type timestamp": (+ "One of the tables you selected to sync is a foreign table whose locally-declared "+ "column is a timestamp type, but the remote server returned a value that isn't a "+ 'valid timestamp (PostgreSQL reported "invalid input syntax for type timestamp"). '+ 'This can happen when a NULL marker from a text-format export (for example "\\N") '+ "wasn't translated to a real NULL. Fix the remote data or the foreign table's column "+ "type, or remove the foreign table from the sync, then re-enable the sync."+ ),}def get_retryable_errors(self) -> set[str]:diff --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 04e57942a50f..5d2f05d2ae38 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@@ -1479,6 +1479,27 @@ class TestPostgresSourceNonRetryableErrors:assert friendly, "FDW column-width mismatch error should surface an actionable message"assert "Widen the local" in friendly[0]+ @pytest.mark.parametrize(+ "error_msg",+ [+ # Raw psycopg message (what the activity-level check sees via str(e)).+ 'invalid input syntax for type timestamp: "\\N"\nCONTEXT: column "created_at" of foreign table "events"',+ # Temporal-wrapped message (what the workflow-level check sees) — carries the class name.+ 'InvalidDatetimeFormat: invalid input syntax for type timestamp: "\\N"',+ ],+ )+ def test_fdw_timestamp_mismatch_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"FDW timestamp mismatch error should be non-retryable: {error_msg}"++ def test_fdw_timestamp_mismatch_returns_friendly_message(self, source):+ non_retryable = source.get_non_retryable_errors()+ error_msg = 'invalid input syntax for type timestamp: "\\N"'+ friendly = [reason for pattern, reason in non_retryable.items() if pattern in error_msg and reason]+ assert friendly, "FDW timestamp mismatch error should surface an actionable message"+ assert "timestamp" in friendly[0]+@pytest.mark.parametrize("error_msg",[