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): stop retrying fdw enum-mismatch reads (#73554)

Tom Owers80540c36042f
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.py
index e624871a0df7..1590e8dca3ba 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
@@ -700,6 +700,21 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa
"connecting role on that foreign server (CREATE USER MAPPING ...), or remove the "
"foreign table from the sync, then re-enable the sync."
),
+ # A selected relation is a postgres_fdw foreign table whose locally-declared enum column
+ # doesn't match the data actually stored on the remote server — the remote row holds a
+ # label the local enum type doesn't define (SQLSTATE 22P02, "invalid input value for enum
+ # <type>: <value>"). Postgres enforces enum labels at write time on ordinary tables, so
+ # this can only surface when reading through a foreign table's separately-declared type.
+ # The schema drift 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 enum
+ # type name and offending value.
+ "invalid input value for enum": (
+ "One of the tables you selected to sync is a foreign table (postgres_fdw) whose "
+ "locally-declared enum column doesn't match the data on the remote server "
+ '(PostgreSQL reported "invalid input value for enum"). Update the local enum type to '
+ "include the value used on the remote server, or remove the foreign table from the "
+ "sync, then re-enable the sync."
+ ),
}
def reconcile_schema_metadata(
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.py
index a16bfac3ece2..0c50b22e3b09 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
@@ -1011,6 +1011,27 @@ class TestPostgresSourceNonRetryableErrors:
assert friendly, "Missing FDW user mapping error should surface an actionable message"
assert "CREATE USER MAPPING" in friendly[0]
+ @pytest.mark.parametrize(
+ "error_msg",
+ [
+ # Raw psycopg message (what the activity-level check sees via str(e)).
+ 'invalid input value for enum "InvitationType": "workshop"\nCONTEXT: column "invitation_type" of foreign table "invitations"',
+ # Temporal-wrapped message (what the workflow-level check sees) — carries the class name.
+ 'InvalidTextRepresentation: invalid input value for enum "InvitationType": "workshop"',
+ ],
+ )
+ def test_fdw_enum_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 enum mismatch error should be non-retryable: {error_msg}"
+
+ def test_fdw_enum_mismatch_returns_friendly_message(self, source):
+ non_retryable = source.get_non_retryable_errors()
+ error_msg = 'invalid input value for enum "InvitationType": "workshop"'
+ friendly = [reason for pattern, reason in non_retryable.items() if pattern in error_msg and reason]
+ assert friendly, "FDW enum mismatch error should surface an actionable message"
+ assert "enum type" in friendly[0]
+
@pytest.mark.parametrize(
"error_msg",
[