: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): guide users who paste host:port into the host field (#91355)
Tom Owers0f8ead0b5d91
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 b2b7859c0251..2e823eebf5df 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@@ -73,6 +73,11 @@ _HOST_IS_URL_ERROR = ("password, port, or path.")+_HOST_HAS_PORT_ERROR = (+ "Enter just the hostname in the host field (for example, db.example.com). Put the port number "+ "in the port field instead."+)+# ENETUNREACH / EHOSTUNREACH at connect time: the host resolved to a public address PostHog can't# route to. The common cause is a host that only accepts IPv6 (PostHog egresses over IPv4) — for# example a Supabase direct-connection host — or a firewall dropping PostHog's IPs. Deterministic@@ -1211,6 +1216,13 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDaif "://" in config.host:return False, _HOST_IS_URL_ERROR+ # A bare "host:port" pasted into the host field (no scheme, so the URL guard above misses it)+ # otherwise fails DNS with a confusing "check the spelling" message that echoes the value+ # back. A bare IPv6 literal has several colons, so guard only the single-colon host:port shape.+ host_value = config.host.strip()+ if host_value.count(":") == 1 and not host_value.startswith("["):+ return False, _HOST_HAS_PORT_ERROR+valid_host, host_errors = self.is_database_host_valid(config.host, team_id, using_ssh_tunnel=self.ssh_tunnel_enabled(config))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 2eba1375a5ef..e21f55681cf8 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@@ -3848,6 +3848,35 @@ class TestValidateCredentialsErrorMapping:assert host not in (error or "")assert "hostname" in (error or "")+ @pytest.mark.parametrize(+ "host",+ [+ "db.example.com:5432", # host:port pasted into the host field+ "db.example.com:", # trailing colon with an empty port+ ],+ )+ def test_port_in_host_field_rejected_before_dns(self, source, host):+ config = source.parse_config(+ {+ "host": host,+ "port": 5432,+ "database": "postgres",+ "user": "postgres",+ "password": "postgres",+ "schema": "public",+ }+ )+ with (+ mock.patch.object(source, "ssh_tunnel_is_valid", return_value=(True, None)),+ mock.patch.object(source, "is_database_host_valid", side_effect=AssertionError("should not resolve")),+ mock.patch.object(source, "get_schemas", side_effect=AssertionError("should not connect")),+ ):+ valid, error = source.validate_credentials(config, team_id=1)++ assert valid is False+ assert host not in (error or "")+ assert "port field" in (error or "")+class TestPostgresSchemaDiscovery:def _mock_connection(self, *fetchall_results: list[tuple[object, ...]]):