: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 missing FDW user mapping as non-retryable (#67508)
Tom Owers27624fbda341
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 20e959c7488d..f2838baa7d71 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@@ -545,6 +545,19 @@ 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 is a postgres_fdw foreign table and the connecting role has no user+ # mapping for the foreign server it points at, so every SELECT fails with+ # "UndefinedObject: user mapping not found for user <user>, server <server>" (SQLSTATE+ # 42704). The mapping is fixed server-side config only the customer can create, so+ # retrying re-reads into the same wall. Match the stable fragment and exclude the volatile+ # user/server names.+ "user mapping not found for": (+ "One of the tables you selected to sync is a foreign table (postgres_fdw), and "+ "PostHog's database role has no user mapping for the foreign server it points at "+ '(PostgreSQL reported "user mapping not found"). Create a user mapping for the '+ "connecting role on that foreign server (CREATE USER MAPPING ...), 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.pyindex 8181248e4a71..3fd698c2f6cb 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@@ -775,6 +775,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)).+ 'user mapping not found for user "svc_role", server "remote_server"',+ # Temporal-wrapped message (what the workflow-level check sees) — carries the class name.+ 'UndefinedObject: user mapping not found for user "svc_role", server "remote_server"',+ ],+ )+ def test_missing_fdw_user_mapping_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"Missing FDW user mapping error should be non-retryable: {error_msg}"++ def test_missing_fdw_user_mapping_returns_friendly_message(self, source):+ non_retryable = source.get_non_retryable_errors()+ error_msg = 'user mapping not found for user "svc_role", server "remote_server"'+ friendly = [reason for pattern, reason in non_retryable.items() if pattern in error_msg and reason]+ assert friendly, "Missing FDW user mapping error should surface an actionable message"+ assert "CREATE USER MAPPING" in friendly[0]+@pytest.mark.parametrize("error_msg",[