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): give a clear message for a rejected database password (#80103)

Tom Owers824091d14d36
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 9e2cac3c4cba..e2e263a9c3f6 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
@@ -81,6 +81,14 @@ _HOST_UNREACHABLE_ERROR = (
"firewall allowlist, then try again."
)
+# Wrong username or password reported by libpq's standard wording or the SCRAM exchange. The raw
+# driver string is prefixed with "connection to server at <host>, port <port> failed", so surface a
+# clean, host-free message on the non-retryable sync path instead of storing that raw prefix.
+_INVALID_CREDENTIALS_ERROR = (
+ "The database rejected the username or password. Check the user and password configured for "
+ "this source, then re-enable the sync."
+)
+
PostgresErrors = {
"password authentication failed for user": "Invalid user or password",
# libpq reports a bad password via SCRAM with a different wording than the line above.
@@ -337,7 +345,7 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa
'"postgres.<project-ref>"). Update the user for this source to the pooler username '
"shown in your Supabase dashboard, then re-enable the sync."
),
- "error received from server in SCRAM exchange: Wrong password": None,
+ "error received from server in SCRAM exchange: Wrong password": _INVALID_CREDENTIALS_ERROR,
# The server (commonly Supabase's Supavisor transaction pooler on port 6543) rejects the
# SASL/SCRAM credential exchange with "FATAL: SASL authentication failed" instead of
# PostgreSQL's "password authentication failed for user" — so none of the password keys
@@ -368,14 +376,14 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDa
),
"could not translate host name": None,
"timeout expired connection to server at": None,
- "password authentication failed for user": None,
+ "password authentication failed for user": _INVALID_CREDENTIALS_ERROR,
# Some providers (observed on a Neon-style pooler) report the same auth rejection without
# libpq's "for user" wording, putting the role on its own line instead: "password
# authentication failed\nuser \"<role>\"". The key above requires "for user" right after
# "failed", so it doesn't substring-match this variant and Temporal keeps retrying a
# credential mismatch only the customer can fix. Match the stable, wording-independent
# fragment shared by both forms.
- "password authentication failed": None,
+ "password authentication failed": _INVALID_CREDENTIALS_ERROR,
# AWS RDS Proxy reports bad credentials with its own wording instead of PostgreSQL's
# "password authentication failed for user" — it validates against Secrets Manager and
# returns "The password that was provided for the role <role> is wrong." None of the
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 2362a94ddc46..0f960d6a07e7 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
@@ -768,6 +768,23 @@ class TestPostgresSourceNonRetryableErrors:
f"Password auth failure without 'for user' wording should be non-retryable: {error_msg}"
)
+ @pytest.mark.parametrize(
+ "error_msg",
+ [
+ 'connection to server at "203.0.113.30", port 5432 failed: FATAL: password authentication failed for user "u"',
+ 'connection to server at "203.0.113.30", port 5432 failed: FATAL: password authentication failed\nuser "u"',
+ "connection failed: error received from server in SCRAM exchange: Wrong password",
+ ],
+ )
+ def test_password_authentication_failure_surfaces_a_host_free_message(self, source, error_msg):
+ # The raw driver string embeds the host/IP and port; the surfaced message must be actionable
+ # and carry neither. Guards a regression back to the raw error (value `None`).
+ non_retryable = source.get_non_retryable_errors()
+ friendly = [reason for pattern, reason in non_retryable.items() if pattern in error_msg and reason]
+ assert friendly, "A rejected password should surface an actionable message"
+ assert "username or password" in friendly[0]
+ assert "203.0.113.30" not in friendly[0]
+
@pytest.mark.parametrize(
"error_msg",
[