: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): name Railway's private host instead of a DNS spelling error (#102115)
Tom Owers2917de4d1aa5
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 bd2043ca38f0..51fd45f4f841 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@@ -85,6 +85,15 @@ _HOST_HAS_PORT_ERROR = ("in the port field instead.")+# Railway's DATABASE_URL points at the service's private-network host, so it is the value customers+# paste most often. The name only resolves inside Railway's own network, and the DNS failure that+# follows asks them to check a spelling that is already correct, so name the public host instead.+_RAILWAY_INTERNAL_HOST_SUFFIX = ".railway.internal"+_RAILWAY_INTERNAL_HOST_ERROR = (+ "Railway's .railway.internal host only resolves inside Railway's private network. Use the "+ "public TCP proxy host and port Railway shows for your database 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@@ -1487,6 +1496,11 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDaif host_value.count(":") == 1 and not host_value.startswith("["):return False, _HOST_HAS_PORT_ERROR+ # A bastion inside the customer's Railway project can reach the private host, so only reject+ # it for a direct connection.+ if not self.ssh_tunnel_enabled(config) and host_value.lower().endswith(_RAILWAY_INTERNAL_HOST_SUFFIX):+ return False, _RAILWAY_INTERNAL_HOST_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 46facf9ab6cb..cfdb58653a61 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@@ -4915,6 +4915,55 @@ class TestValidateCredentialsErrorMapping:assert host not in (error or "")assert "port field" in (error or "")+ def test_railway_private_host_named_as_such_instead_of_a_spelling_error(self, source):+ config = source.parse_config(+ {+ "host": "postgres.railway.internal",+ "port": 5432,+ "database": "railway",+ "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 "private network" in (error or "")+ # The host is spelled correctly, so the generic DNS guidance would send the user in circles.+ assert "spelled correctly" not in (error or "")++ def test_railway_private_host_still_allowed_through_an_ssh_tunnel(self, source):+ config = source.parse_config(+ {+ "host": "postgres.railway.internal",+ "port": 5432,+ "database": "railway",+ "user": "postgres",+ "password": "postgres",+ "schema": "public",+ "ssh_tunnel": {+ "enabled": True,+ "host": "bastion.example.com",+ "port": "22",+ "auth": {"selection": "password", "username": "tunnel", "password": "tunnel"},+ },+ }+ )+ with (+ mock.patch.object(source, "ssh_tunnel_is_valid", return_value=(True, None)),+ mock.patch.object(source, "is_database_host_valid", return_value=(True, None)),+ mock.patch.object(source, "get_schemas", return_value=[]),+ ):+ valid, error = source.validate_credentials(config, team_id=1)++ assert (valid, error) == (True, None)+class TestPostgresSchemaDiscovery:def _mock_connection(self, *fetchall_results: list[tuple[object, ...]]):