: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): guard host validation for configs without an ssh tunnel (#82384)
Tom Owers251d03106f99
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/planetscale_postgres/test_planetscale_postgres_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/planetscale_postgres/test_planetscale_postgres_source.pyindex 744fdd06f02d..969a2da022fb 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/planetscale_postgres/test_planetscale_postgres_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/planetscale_postgres/test_planetscale_postgres_source.py@@ -115,6 +115,28 @@ def test_database_host_is_passed_through_to_postgres():assert error is None+def test_validate_credentials_handles_a_config_without_an_ssh_tunnel_field():+ # The generated PlanetScale config carries no `ssh_tunnel` field (there is no tunnel to+ # configure), so the inherited Postgres validation must not assume the attribute exists.+ planetscale_config = PlanetScalePostgresSourceConfig(+ host=_DIRECT_HOST,+ database="postgres",+ user="postgres.xxxxxxxxxx",+ password="pscale_pw_xxxxxxxx",+ port=5432,+ )+ assert not hasattr(planetscale_config, "ssh_tunnel")++ with mock.patch.object(PostgresSource, "is_database_host_valid", return_value=(False, "host error")) as host_valid:+ # The signature annotates PostgresSourceConfig, but the pipeline hands this source its own+ # generated config at runtime — the exact mismatch that surfaced the missing attribute.+ success, error = PlanetScalePostgresSource().validate_credentials(planetscale_config, team_id=1) # type: ignore[arg-type]++ assert success is False+ assert error == "host error"+ assert host_valid.call_args.kwargs["using_ssh_tunnel"] is False++@pytest.mark.parametrize("port", [6432, "6432"])def test_cdc_on_the_psbouncer_port_fails_without_connecting(port):# PSBouncer accepts normal connections, so the generic prerequisite checks would pass whilediff --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 bcd482e058fb..cc651418935c 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@@ -1104,7 +1104,7 @@ class PostgresSource(SQLSource[PostgresSourceConfig], SSHTunnelMixin, ValidateDareturn False, _HOST_IS_URL_ERRORvalid_host, host_errors = self.is_database_host_valid(- config.host, team_id, using_ssh_tunnel=config.ssh_tunnel.enabled if config.ssh_tunnel else False+ config.host, team_id, using_ssh_tunnel=self.ssh_tunnel_enabled(config))if not valid_host:return valid_host, host_errors