: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 MySQL connect failures an actionable error message (#85338)
Tom Owers8e7ed2206edf
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 a499b2718796..4abe0b1a8b49 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@@ -178,7 +178,19 @@ class MySQLSource(SQLSource[MySQLSourceConfig], SSHTunnelMixin, ValidateDatabasedef get_non_retryable_errors(self) -> dict[str, str | None]:return {- "Can't connect to MySQL server on": None,+ # pymysql collapses every connect-level failure (wrong host/port, closed firewall,+ # unreachable host, a connect timeout that outlasts the in-process retry budget) into+ # error 2003, "Can't connect to MySQL server on '<host>' (<os detail>)". Non-retryable+ # for the same reason as the Postgres source's connect-timeout entry: a persistently+ # unreachable host won't recover on retry. Give the actionable reachability guidance the+ # raw driver tuple lacks; the volatile host/os-detail are excluded from the match. The+ # create-time `_VALIDATE_CONNECTION_HINTS` above stay more granular.+ "Can't connect to MySQL server on": (+ "PostHog couldn't connect to your MySQL server. Check that the host and port are "+ "correct and that the database is reachable from the public internet, with PostHog's "+ "egress IP addresses allowed through your firewall. For a database that can't be "+ "exposed publicly, use the SSH tunnel option, then re-enable the sync."+ ),"No primary key defined for table": ("This table needs a primary key to sync incrementally, but none is set. Choose a primary ""key for the table in its sync settings, or switch it to full table replication, then "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 bd97f2046692..dc69adae335a 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@@ -1879,6 +1879,25 @@ class TestMySQLSourceNonRetryableErrors:def source(self):return MySQLSource()+ @pytest.mark.parametrize(+ "error_msg",+ [+ "(2003, \"Can't connect to MySQL server on 'db.example.com' (timed out)\")",+ "(2003, \"Can't connect to MySQL server on 'db.example.com' ([Errno 111] Connection refused)\")",+ ],+ )+ def test_cannot_connect_surfaces_actionable_message(self, source, error_msg):+ # A persistent connect failure is non-retryable, but the customer must get reachability+ # guidance rather than the raw pymysql (2003, ...) tuple. Guards against reverting the+ # umbrella message back to None.+ non_retryable = source.get_non_retryable_errors()+ friendly = next(+ (message for pattern, message in non_retryable.items() if pattern in error_msg),+ None,+ )+ assert friendly is not None, f"Connect failure should surface a friendly message: {error_msg}"+ assert "SSH tunnel" in friendly+@pytest.mark.parametrize("error_msg",[