From 73facf1a7376030b830562efcbd0aaf712c4394f Mon Sep 17 00:00:00 2001 From: Theekshna Kotian Date: Thu, 22 Oct 2026 11:04:03 +0530 Subject: [PATCH] FIX: Deflake arrow reader cross-thread cancel test test_arrow_reader_cancel_from_other_thread: accept OperationalError for HY008 (Operation canceled) when SQLCancel lands mid-fetch; re-raise others. GitHub Issue: #856 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: fe8e84e6-37b7-49d5-b0ca-09c5d1adb60c --- tests/test_004_cursor_arrow.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_004_cursor_arrow.py b/tests/test_004_cursor_arrow.py index 37a336789..573cfa845 100644 --- a/tests/test_004_cursor_arrow.py +++ b/tests/test_004_cursor_arrow.py @@ -533,6 +533,13 @@ def closer(): pytest.fail("reader was not cancelled by the other thread") except pa.ArrowInvalid: pass # acceptable: reader was closed mid-iteration + except mssql_python.OperationalError as e: + # Acceptable: SQLCancel landed while the driver was inside the fetch, + # so the fetch returned SQLSTATE HY008 (ODBC-specified behaviour). + # HY008 is the only SQLSTATE mapped to driver_error "Operation canceled"; + # any other OperationalError is a real failure. + if getattr(e, "driver_error", None) != "Operation canceled": + raise closer_done.wait(timeout=5) t.join(timeout=5)