: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): stop capturing expected connection errors during validation (#64029)
Tom Owersdccc8bf33d13
diff --git a/posthog/temporal/data_imports/sources/mysql/source.py b/posthog/temporal/data_imports/sources/mysql/source.pyindex 14ce71ae9370..afac87619b1f 100644--- a/posthog/temporal/data_imports/sources/mysql/source.py+++ b/posthog/temporal/data_imports/sources/mysql/source.py@@ -179,6 +179,20 @@ class MySQLSource(SQLSource[MySQLSourceConfig], SSHTunnelMixin, ValidateDatabaseor f"Could not connect to {self.get_source_config.name} via the SSH tunnel. Please check all connection details are valid.",)except Exception as e:+ # Connection/credential failures we already classify as non-retryable during sync+ # (an unreachable host, a refused connection, a blocked host, an SSL mismatch, ...)+ # are expected user/upstream errors, not bugs on our side. Surface the friendly+ # message without reporting them to error tracking — only genuinely unexpected+ # failures get captured. Mirrors the Postgres and MSSQL `validate_credentials` handling.+ error_msg = " ".join(str(arg) for arg in e.args) if e.args else str(e)+ for pattern, friendly_error in self.get_non_retryable_errors().items():+ if pattern in error_msg:+ return (+ False,+ friendly_error+ or f"Could not connect to {self.get_source_config.name}. Please check all connection details are valid.",+ )+capture_exception(e)return (False,diff --git a/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.py b/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.pyindex d6ffb2107d36..e452ee2a9798 100644--- a/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.py+++ b/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.py@@ -911,3 +911,46 @@ class TestMySQLSourceNonRetryableErrors:non_retryable = source.get_non_retryable_errors()is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())assert not is_non_retryable, f"Transient thread-exhaustion error should remain retryable: {error_msg}"+++class TestMySQLSourceValidateCredentials:+ @pytest.fixture+ def source(self, mocker):+ source = MySQLSource()+ mocker.patch.object(source, "ssh_tunnel_is_valid", return_value=(True, None))+ mocker.patch.object(source, "is_database_host_valid", return_value=(True, None))+ return source++ @pytest.mark.parametrize(+ "raised",+ [+ # The exact error that fired this triage: an unreachable host surfaces as a+ # pymysql OperationalError(2003) wrapping an OSError — already non-retryable.+ pymysql.err.OperationalError(+ 2003, "Can't connect to MySQL server on 'db.example.com' ([Errno 101] Network is unreachable)"+ ),+ pymysql.err.OperationalError(+ 2003, "Can't connect to MySQL server on 'db.example.com' ([Errno 111] Connection refused)"+ ),+ pymysql.err.OperationalError(1045, "Access denied for user 'u'@'1.2.3.4' (using password: YES)"),+ ],+ )+ def test_known_connection_errors_are_not_captured(self, source, mocker, raised):+ capture = mocker.patch("posthog.temporal.data_imports.sources.mysql.source.capture_exception")+ mocker.patch.object(source, "get_schemas", side_effect=raised)++ valid, error = source.validate_credentials(_make_config(), team_id=1)++ assert valid is False+ assert error is not None+ capture.assert_not_called()++ def test_unexpected_errors_are_still_captured(self, source, mocker):+ capture = mocker.patch("posthog.temporal.data_imports.sources.mysql.source.capture_exception")+ mocker.patch.object(source, "get_schemas", side_effect=RuntimeError("something genuinely unexpected"))++ valid, error = source.validate_credentials(_make_config(), team_id=1)++ assert valid is False+ assert error is not None+ capture.assert_called_once()