: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-level SELECT denied (1142) as non-retryable (#65705)
Tom Owers76a480842cf2
diff --git a/posthog/temporal/data_imports/sources/mysql/source.py b/posthog/temporal/data_imports/sources/mysql/source.pyindex 99d81a666f9e..ceaacece2953 100644--- a/posthog/temporal/data_imports/sources/mysql/source.py+++ b/posthog/temporal/data_imports/sources/mysql/source.py@@ -232,6 +232,13 @@ class MySQLSource(SQLSource[MySQLSourceConfig], SSHTunnelMixin, ValidateDatabase# egress / SSH-tunnel host) — retrying connects from the same host fails identically.# Match the stable tail phrase, not the volatile host in the message prefix."is not allowed to connect to this MySQL server": "Your MySQL/MariaDB server isn't allowing connections from PostHog's host (error 1130). Ask your database admin to grant access for the connecting host (or allow our IP / SSH-tunnel host), then retry the sync.",+ # MySQL/MariaDB error 1142 (ER_TABLEACCESS_DENIED_ERROR): the connecting user authenticated+ # fine but lacks the SELECT privilege on a table the sync reads — distinct from the 1045+ # login failure already handled above. Only a DB admin can GRANT it, and the streaming query+ # reissues the same statement every attempt, so it fails identically forever. Match the+ # locale-independent error code (the user, host, and table are volatile and the message text+ # is translated on non-English servers), consistent with the other code-prefixed entries.+ "(1142,": "PostHog's database user doesn't have SELECT permission on a table this sync reads (MySQL error 1142). Ask your database admin to grant SELECT on it, or remove that table from the sync, then resync.",}def reconcile_schema_metadata(diff --git a/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.py b/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.pyindex 019bb2194e5e..9bddf830f13e 100644--- a/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.py+++ b/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.py@@ -1352,6 +1352,25 @@ class TestMySQLSourceNonRetryableErrors:is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())assert is_non_retryable, f"Host-not-privileged 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(+ 1142, "SELECT command denied to user 'reader'@'10.0.1.5' for table 'orders'"+ )+ ),+ # Temporal-wrapped str(e.cause) form — different user/host/table, same stable code.+ "OperationalError: (1142, \"SELECT command denied to user 'ro'@'10.0.1.5' for table 'events'\")",+ ],+ )+ def test_table_access_denied_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-access-denied error should be non-retryable: {error_msg}"+@pytest.mark.parametrize("error_msg",[