: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 non-latin-1 connection fields as non-retryable (#72452)
Tom Owers682e77d03bd6
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 54340bdf1c1f..d906319bffeb 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@@ -271,6 +271,14 @@ class MySQLSource(SQLSource[MySQLSourceConfig], SSHTunnelMixin, ValidateDatabase# locale-independent error code (the trailing message text is translated on non-English# servers) so it catches both the raw pymysql string and the wrapped `(1038, ...)` form."(1038,": "Your MySQL/MariaDB server ran out of sort buffer memory while ordering this table by its incremental field (error 1038). We try to avoid the sort by forcing the incremental field's index, but this table has no usable index on that field. Add an index on the incremental field, raise the server's 'sort_buffer_size', or switch this table to a full re-sync, then resync.",+ # pymysql encodes the handshake fields (host, user, password, database) as latin-1;+ # a value carrying a non-latin-1 character — most often an invisible zero-width space+ # (U+200B) pasted in from another app — raises UnicodeEncodeError before any packet is+ # sent, so the connect fails identically on every retry. Match the codec's stable+ # range-256 reason, not the volatile character/position: it appears in the raw str(exc)+ # the sync path classifies and in the " ".join(e.args) form validate_credentials builds+ # (the formatted "codec can't encode character" text is reconstructed in neither).+ "ordinal not in range(256)": "One of your connection details contains an invisible or unsupported character (for example a zero-width space pasted in from another app). Retype the affected field — host, database, user, or password — by hand instead of pasting it, then re-enable the sync.",}def reconcile_schema_metadata(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 50c7587ee9b4..912ff2398721 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@@ -1847,6 +1847,23 @@ class TestMySQLSourceNonRetryableErrors:is_non_retryable = any(pattern in error_msg for pattern in non_retryable.keys())assert is_non_retryable, f"Out-of-sort-memory error should be non-retryable: {error_msg}"+ @pytest.mark.parametrize(+ "error_msg",+ [+ # str(exc) form the sync path classifies — a zero-width space pasted into a field.+ str(UnicodeEncodeError("latin-1", "\u200b", 0, 1, "ordinal not in range(256)")),+ # `" ".join(str(arg) for arg in exc.args)` form validate_credentials builds, where the+ # formatted "codec can't encode character" text is absent but the reason arg remains.+ " ".join(str(a) for a in UnicodeEncodeError("latin-1", "\u200b", 0, 1, "ordinal not in range(256)").args),+ # A different offending character and position stays matched.+ str(UnicodeEncodeError("latin-1", "\u3042", 4, 5, "ordinal not in range(256)")),+ ],+ )+ def test_non_latin1_connection_field_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"Non-latin-1 connection field error should be non-retryable: {error_msg}"+@pytest.mark.parametrize("error_msg",[