: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): stop flooding error tracking from best-effort row-count probe (#63755)
Tom Owersa50c11fbcbd9
diff --git a/posthog/temporal/data_imports/sources/mysql/mysql.py b/posthog/temporal/data_imports/sources/mysql/mysql.pyindex fab8d1b8c474..84f9db8f1c96 100644--- a/posthog/temporal/data_imports/sources/mysql/mysql.py+++ b/posthog/temporal/data_imports/sources/mysql/mysql.py@@ -593,8 +593,13 @@ class MySQLImplementation(SQLSourceImplementation[MySQLSourceConfig, pymysql.Conlogger.debug(f"get_rows_to_sync: rows_to_sync_int={rows_to_sync_int}")return rows_to_sync_intexcept Exception as e:+ # This COUNT(*) is a best-effort estimate for progress reporting and partition sizing.+ # It shares its FROM/WHERE with the real streaming query, so any genuine problem+ # (missing column, bad incremental field, permissions) resurfaces there and is+ # classified through the normal retryable/non-retryable path. The MAX_EXECUTION_TIME+ # hint above also makes timeouts here expected. Capturing it would only flood error+ # tracking with handled duplicates, so we log at debug and fall back to 0.logger.debug(f"get_rows_to_sync: Error: {e}. Using 0 as rows to sync", exc_info=e)- capture_exception(e)return 0def fetch_table_stats(diff --git a/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.py b/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.pyindex 3960925189e3..3d4b7bd97365 100644--- a/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.py+++ b/posthog/temporal/data_imports/sources/mysql/tests/test_mysql.py@@ -291,6 +291,26 @@ class TestGetRowsToSync:# Swallows the error rather than propagating — matches pre-refactor behavior.assert impl.get_rows_to_sync(cursor, "SELECT * FROM t", {}, logger) == 0+ @pytest.mark.parametrize(+ "error",+ [+ pymysql.err.OperationalError(1054, "Unknown column 'favoritor_id' in 'where clause'"),+ pymysql.err.OperationalError(+ 3024, "Query execution was interrupted, maximum statement execution time exceeded"+ ),+ RuntimeError("boom"),+ ],+ )+ def test_does_not_capture_handled_probe_failures(self, impl, cursor, logger, error, mocker):+ # The COUNT(*) probe is best-effort: it falls back to 0 and must not flood error+ # tracking with handled failures (e.g. a bad incremental field or the MAX_EXECUTION_TIME+ # timeout). Genuine problems resurface in the real streaming query and are classified there.+ cursor.execute.side_effect = error+ capture = mocker.patch("posthog.temporal.data_imports.sources.mysql.mysql.capture_exception")++ assert impl.get_rows_to_sync(cursor, "SELECT * FROM t", {}, logger) == 0+ capture.assert_not_called()+def test_wraps_inner_query_as_subselect(self, impl, cursor, logger):cursor.fetchone.return_value = (5,)impl.get_rows_to_sync(cursor, "SELECT x FROM y WHERE a = %(a)s", {"a": 1}, logger)