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): stop retrying syncs against a dropped/renamed database (#76515)

Tom Owers2e59bdb2331d
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.py
index 8fe8321e685e..4af7467f9a3f 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
@@ -179,6 +179,15 @@ class MySQLSource(SQLSource[MySQLSourceConfig], SSHTunnelMixin, ValidateDatabase
# 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",
+ # MySQL/MariaDB error 1049 (ER_BAD_DB_ERROR): the configured database doesn't exist on
+ # the server — it was renamed or dropped after the source was set up, or the connection
+ # was reconfigured to point at a different server. `validate_credentials` already
+ # catches this at create time via `_VALIDATE_CONNECTION_HINTS`, but that hint only fires
+ # on the create-time probe; a database dropped later only surfaces here, mid-sync. Every
+ # retry connects with the same database name and fails identically. Match the
+ # locale-independent error code (the database name is volatile and the message text is
+ # translated on non-English servers).
+ "(1049,": "The database configured for this source no longer exists (MySQL error 1049). It may have been renamed or dropped. Update the database name in your source settings, or restore it, then resync.",
"sqlstate 42S02": None, # Table not found error
# MySQL/MariaDB error 1146 (ER_NO_SUCH_TABLE): a table the sync reads no longer exists
# in the source — it was renamed or dropped after the schema was set up. The streaming
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.py
index bbbde3ef15e6..404fa0704c1e 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
@@ -1896,6 +1896,21 @@ class TestMySQLSourceNonRetryableErrors:
is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())
assert is_non_retryable, f"Table-not-found error should be non-retryable: {error_msg}"
+ @pytest.mark.parametrize(
+ "error_msg",
+ [
+ # Raw pymysql str(error) form the import/sync path classifies (`_handle_import_error`
+ # matches `str(error)`, which has no class-name prefix).
+ str(pymysql.err.OperationalError(1049, "Unknown database 'wealth_insights'")),
+ # Temporal-wrapped / refresh-schemas form that prepends the exception class name.
+ "OperationalError: (1049, \"Unknown database 'wealth_insights'\")",
+ ],
+ )
+ def test_unknown_database_is_non_retryable(self, source, error_msg):
+ non_retryable = source.get_non_retryable_errors()
+ is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())
+ assert is_non_retryable, f"Unknown-database error should be non-retryable: {error_msg}"
+
@pytest.mark.parametrize(
"error_msg",
[