FIX: Preserve Arrow reader fetch exceptions (#712) - #718
Open
Subrata (subrata-ms) wants to merge 5 commits into
Open
FIX: Preserve Arrow reader fetch exceptions (#712)#718Subrata (subrata-ms) wants to merge 5 commits into
Subrata (subrata-ms) wants to merge 5 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Cursor.arrow_reader() cleanup semantics in mssql_python/cursor.py so fetch exceptions from the Arrow batch generator are not accidentally discarded, addressing Python 3.14+ warnings-as-errors behavior (PEP 765) and improving robustness around teardown paths.
Changes:
- Refactors the
arrow_reader()batch generatorfinallycleanup guard to avoidreturninfinallyand preserve in-flight fetch exceptions. - Adds Arrow-reader tests that assert fetch errors propagate both when cleanup is skipped and when cleanup runs normally.
- Adds a Python 3.14+ test that compiles
mssql_python/cursor.pyunder warnings-as-errors to catch future “return in finally” regressions.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| mssql_python/cursor.py | Removes the return-in-finally pattern in Arrow reader cleanup by converting it to a conditional cleanup block, preserving exceptions. |
| tests/test_004_cursor_arrow.py | Adds regression tests ensuring Arrow reader fetch errors are not masked by defensive cleanup paths. |
| tests/test_004_cursor.py | Adds a Python 3.14+ compilation test to ensure cursor.py compiles cleanly with warnings promoted to errors. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Subrata (subrata-ms)
requested review from
Gaurav Sharma (bewithgaurav),
gargsaumya,
Jahnvi Thakkar (jahnvi480) and
Sumit Sarabhai (sumitmsft)
August 13, 2026 05:51
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Work Item / Issue Reference
Summary
This pull request improves the robustness and test coverage of the cursor cleanup logic in the
mssql_pythonpackage, particularly around error handling during fetch operations and resource cleanup. It also introduces a build check to ensure that the driver source code compiles cleanly with warnings treated as errors in Python 3.14 and above.Error handling and cleanup improvements:
batch_generator()incursor.pyto only skip cleanup if the cursor isNone, closed, or has nohstmt, improving clarity and correctness.Test coverage enhancements:
test_004_cursor_arrow.pyto verify that fetch errors are properly propagated and not masked by defensive cleanup logic, both when cleanup is skipped and after normal cleanup. These tests use fake cursor objects to simulate various error and cleanup scenarios.Build and compatibility checks:
test_004_cursor.pyto ensure thatcursor.pycompiles successfully withSyntaxWarningpromoted to an error, as required by Python 3.14+ (PEP 765). This helps future-proof the codebase against upcoming Python changes.subprocess,sys,Path) intest_004_cursor.pyto support the new compilation test.