Skip to content

: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.

fix(mysql): surface invalid credentials as an auth error, not a generic one (#64224)

Tom Owers9f127549914a
diff --git a/posthog/temporal/data_imports/sources/mysql/source.py b/posthog/temporal/data_imports/sources/mysql/source.py
index afac87619b1f..c89810421c35 100644
--- a/posthog/temporal/data_imports/sources/mysql/source.py
+++ b/posthog/temporal/data_imports/sources/mysql/source.py
@@ -116,7 +116,11 @@ class MySQLSource(SQLSource[MySQLSourceConfig], SSHTunnelMixin, ValidateDatabase
return {
"Can't connect to MySQL server on": None,
"No primary key defined for table": None,
- "Access denied for user": None,
+ # MySQL/MariaDB error 1045 (ER_ACCESS_DENIED_ERROR): the user/password (or the
+ # user's host grant) is wrong. Surface it as an auth failure — mirroring the Postgres
+ # source — so the user fixes credentials instead of the generic "check connection
+ # details" message sending them to check the host/port.
+ "Access denied for user": "Invalid user or password",
"sqlstate 42S02": None, # Table not found error
"ProgrammingError: (1146": None, # Table not found error
"OperationalError: (1356": None, # View not found error
diff --git a/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.py b/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.py
index f6c822d73a07..50152ab08532 100644
--- a/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.py
+++ b/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.py
@@ -983,27 +983,39 @@ class TestMySQLSourceValidateCredentials:
return source
@pytest.mark.parametrize(
- "raised",
+ "raised,expected_error",
[
# 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)"
+ # A connection failure keeps the generic "check connection details" message.
+ (
+ pymysql.err.OperationalError(
+ 2003, "Can't connect to MySQL server on 'db.example.com' ([Errno 101] Network is unreachable)"
+ ),
+ "Could not connect to MySQL. Please check all connection details are valid.",
),
- pymysql.err.OperationalError(
- 2003, "Can't connect to MySQL server on 'db.example.com' ([Errno 111] Connection refused)"
+ (
+ pymysql.err.OperationalError(
+ 2003, "Can't connect to MySQL server on 'db.example.com' ([Errno 111] Connection refused)"
+ ),
+ "Could not connect to MySQL. Please check all connection details are valid.",
+ ),
+ # An auth failure (error 1045) must name the credentials, not the generic message
+ # that sends the user to inspect the host/port instead. Mirrors Postgres.
+ (
+ pymysql.err.OperationalError(1045, "Access denied for user 'u'@'1.2.3.4' (using password: YES)"),
+ "Invalid user or password",
),
- 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):
+ def test_known_connection_errors_are_not_captured(self, source, mocker, raised, expected_error):
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
+ assert error == expected_error
capture.assert_not_called()
def test_unexpected_errors_are_still_captured(self, source, mocker):