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): treat FDW column-width mismatches as non-retryable (#78611)

Tom Owers6ca14fc6a8be
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 130e1ff8df84..23c59b50b133 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
@@ -758,6 +758,20 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa
"include the value used on the remote server, 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 character
+ # column is narrower than the data actually stored on the remote server (SQLSTATE 22001,
+ # "value too long for type character varying(<n>)"). Postgres enforces length constraints
+ # at write time on ordinary tables, so this can only surface via a foreign table's
+ # separately-declared width. 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 declared width and the CONTEXT line's column/table names.
+ "value too long for type character": (
+ "One of the tables you selected to sync is a foreign table (postgres_fdw) whose "
+ "locally-declared column is narrower than the data on the remote server "
+ '(PostgreSQL reported "value too long for type character..."). Widen the local '
+ "column's declared length to match the remote server, 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.py
index 331cec4e7234..3cb3c63b1c09 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
@@ -1113,6 +1113,27 @@ class TestPostgresSourceNonRetryableErrors:
assert friendly, "FDW enum mismatch error should surface an actionable message"
assert "enum type" in friendly[0]
+ @pytest.mark.parametrize(
+ "error_msg",
+ [
+ # Raw psycopg message (what the activity-level check sees via str(e)).
+ 'value too long for type character varying(3)\nCONTEXT: column "currency" of foreign table "accounttransaction"',
+ # Temporal-wrapped message (what the workflow-level check sees) — carries the class name.
+ "StringDataRightTruncation: value too long for type character varying(3)",
+ ],
+ )
+ def test_fdw_string_truncation_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 column-width mismatch error should be non-retryable: {error_msg}"
+
+ def test_fdw_string_truncation_returns_friendly_message(self, source):
+ non_retryable = source.get_non_retryable_errors()
+ error_msg = 'value too long for type character varying(3)\nCONTEXT: column "currency" of foreign table "accounttransaction"'
+ friendly = [reason for pattern, reason in non_retryable.items() if pattern in error_msg and reason]
+ assert friendly, "FDW column-width mismatch error should surface an actionable message"
+ assert "Widen the local" in friendly[0]
+
@pytest.mark.parametrize(
"error_msg",
[