: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): treat table-not-found (error 1146) as non-retryable during sync (#64584)
Tom Owers2d7bc7446469
diff --git a/posthog/temporal/data_imports/sources/mysql/source.py b/posthog/temporal/data_imports/sources/mysql/source.pyindex e334579a9c3e..01c4a1b1e384 100644--- a/posthog/temporal/data_imports/sources/mysql/source.py+++ b/posthog/temporal/data_imports/sources/mysql/source.py@@ -130,8 +130,25 @@ class MySQLSource(SQLSource[MySQLSourceConfig], SSHTunnelMixin, ValidateDatabase# 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+ # 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+ # query reissues the same statement on every attempt, so it fails identically forever.+ # Match the locale-independent error code (the table name is volatile and the message+ # text is translated on non-English servers): `(1146,` appears both in the raw pymysql+ # `str(exc)` the import/sync path classifies — `(1146, "Table ... doesn't exist")` — and+ # in the class-name-prefixed `ProgrammingError: (1146, ...)` form the refresh-schemas+ # path builds. The previous `"ProgrammingError: (1146"` key only matched the latter, so+ # sync hit this error retried to the maximum instead of stopping.+ "(1146,": "A table this sync reads no longer exists in your source database (MySQL error 1146). It was most likely renamed or dropped — restore the table, or remove it from the sync, then resync.",+ # MySQL/MariaDB error 1356 (ER_VIEW_INVALID): a view the sync reads is broken — it+ # references tables/columns that were dropped or renamed, or the view's definer lost the+ # rights to read them. The streaming query reissues the same statement every attempt, so+ # it fails identically forever. Match the locale-independent code `(1356,`, which appears+ # both in the raw pymysql `str(exc)` the import/sync path classifies — `(1356, "View ...+ # references invalid table(s) ...")` — and in the class-name-prefixed+ # `OperationalError: (1356, ...)` form the refresh-schemas path builds. The previous+ # `"OperationalError: (1356"` key only matched the latter.+ "(1356,": "A view this sync reads is no longer valid (MySQL error 1356). It references tables or columns that were dropped or renamed, or its definer lost access to them — fix the view definition in your source database, or remove it from the sync, then resync.","Bad handshake": None,# Raised by the `sshtunnel` library (via the shared `open_ssh_tunnel` helper) when the# SSH tunnel can't be brought up — the bastion host is unreachable, the host/port isdiff --git a/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.py b/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.pyindex cc00af6696b9..da9cf3b42b86 100644--- a/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.py+++ b/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.py@@ -1172,6 +1172,40 @@ class TestMySQLSourceNonRetryableErrors:is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())assert is_non_retryable, f"Unknown-column 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.ProgrammingError(1146, "Table 'defaultdb.wealth_insights' doesn't exist")),+ # Temporal-wrapped / refresh-schemas form that prepends the exception class name.+ "ProgrammingError: (1146, \"Table 'defaultdb.wealth_insights' doesn't exist\")",+ ],+ )+ def test_table_not_found_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"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(+ 1356, "View 'defaultdb.wealth_view' references invalid table(s) or column(s)"+ )+ ),+ # Temporal-wrapped / refresh-schemas form that prepends the exception class name.+ "OperationalError: (1356, \"View 'defaultdb.wealth_view' references invalid table(s) or column(s)\")",+ ],+ )+ def test_invalid_view_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"Invalid-view error should be non-retryable: {error_msg}"+@pytest.mark.parametrize("error_msg",[