: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(mysql): give actionable error when a URL is entered as the host (#68369)
Tom Owersde145eb081ee
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/source.pyindex 69571867c87b..a0cce58a2971 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/source.py@@ -72,6 +72,12 @@ _VALIDATE_CONNECTION_HINTS: list[tuple[str, str]] = [("Unknown database", "Database does not exist. Check the database name is correct."),]+_HOST_IS_URL_ERROR = (+ "Enter just the hostname in the host field (for example, db.example.com), not a full URL or "+ "connection string. Remove any scheme (like http:// or mysql://) and any username, password, "+ "port, or path."+)+@SourceRegistry.registerclass MySQLSource(SQLSource[MySQLSourceConfig], SSHTunnelMixin, ValidateDatabaseHostMixin):@@ -286,6 +292,12 @@ class MySQLSource(SQLSource[MySQLSourceConfig], SSHTunnelMixin, ValidateDatabaseif not is_ssh_valid:return is_ssh_valid, ssh_valid_errors+ # A pasted URL or connection string in the host field otherwise fails DNS resolution with a+ # misleading "check the spelling" message that echoes the raw value back (which can embed+ # credentials). Catch it early with an actionable message that never reflects the input.+ if "://" in config.host:+ return False, _HOST_IS_URL_ERROR+valid_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)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/tests/test_mysql.py b/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/tests/test_mysql.pyindex 73a18b0a8ceb..583aa522249d 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/tests/test_mysql.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/mysql/tests/test_mysql.py@@ -1687,6 +1687,25 @@ class TestMySQLSourceValidateCredentials:assert error == expected_errorcapture.assert_not_called()+ @pytest.mark.parametrize(+ "host",+ [+ "https://db.example.com/",+ "mysql://root:[email protected]:3306/mydb",+ ],+ )+ def test_url_in_host_field_rejected_without_echoing_input(self, source, mocker, host):+ # If the guard is dropped, the raw host reaches host validation / DNS and the+ # message would echo it (leaking a pasted password), so assert it is never reached.+ mocker.patch.object(source, "is_database_host_valid", side_effect=AssertionError("should not resolve"))+ mocker.patch.object(source, "get_schemas", side_effect=AssertionError("should not connect"))++ valid, error = source.validate_credentials(_make_config(host=host), team_id=1)++ assert valid is False+ assert host not in (error or "")+ assert "hostname" in (error or "")+def test_unexpected_errors_are_still_captured(self, source, mocker):capture = mocker.patch("products.warehouse_sources.backend.temporal.data_imports.sources.mysql.source.capture_exception"