@@ -951,23 +951,27 @@ def timeout_side_effect(*args, **kwargs):
951951 conn_mock .ping .assert_not_called ()
952952 close_spy .assert_called_once ()
953953
954- # Write statements (e.g. INSERT) must NOT be retried after OperationalError(2013) to avoid duplicating rows
955- conn_mock .reset_mock ()
956- close_spy .reset_mock ()
957- write_calls = 0
954+ # Write statements (e.g. INSERT or CTE-prefixed INSERT) must NOT be retried after OperationalError(2013) to avoid duplicating rows
955+ for unsafe_write_sql in (
956+ "INSERT INTO `tbl` VALUES (1)" ,
957+ "WITH `cte` AS (SELECT 1) INSERT INTO `tbl` SELECT * FROM `cte`" ,
958+ ):
959+ conn_mock .reset_mock ()
960+ close_spy .reset_mock ()
961+ write_calls = 0
958962
959- def write_side_effect (* args , ** kwargs ):
960- nonlocal write_calls
961- write_calls += 1
962- raise OperationalError (2013 , "Lost connection to MySQL server during query" )
963+ def write_side_effect (* args , ** kwargs ):
964+ nonlocal write_calls
965+ write_calls += 1
966+ raise OperationalError (2013 , "Lost connection to MySQL server during query" )
963967
964- adapter .cursor .execute .side_effect = write_side_effect
965- with pytest .raises (OperationalError ):
966- adapter . _execute ( "INSERT INTO `tbl` VALUES (1)" )
968+ adapter .cursor .execute .side_effect = write_side_effect
969+ with pytest .raises (OperationalError ):
970+ adapter . _execute ( unsafe_write_sql )
967971
968- assert write_calls == 1
969- conn_mock .ping .assert_not_called ()
970- close_spy .assert_called_once ()
972+ assert write_calls == 1
973+ conn_mock .ping .assert_not_called ()
974+ close_spy .assert_called_once ()
971975
972976
973977def test_external_catalog_view_error_and_drop_noop (
@@ -2203,6 +2207,14 @@ def fake_read_sql_query(sql, con, *args, **kwargs):
22032207 assert fetch_calls == 2
22042208 assert close_spy .call_count == 1
22052209
2210+ # 4. _fetch_native_df does NOT retry non-read-only queries on disconnect
2211+ fetch_calls = 0
2212+ close_spy .reset_mock ()
2213+ with pytest .raises (OperationalError ):
2214+ adapter .fetchdf ("WITH `cte` AS (SELECT 1) INSERT INTO `tbl` SELECT * FROM `cte`" )
2215+ assert fetch_calls == 1
2216+ assert close_spy .call_count == 1
2217+
22062218
22072219def test_strip_for_update_and_multi_col_index_and_partition_by_alias_and_deferred_mv_audit_refresh (
22082220 make_mocked_engine_adapter : t .Callable [..., DorisEngineAdapter ],
0 commit comments