Skip to content

FIX: Preserve Arrow reader fetch exceptions (#712) - #718

Open
Subrata (subrata-ms) wants to merge 5 commits into
mainfrom
subrata-ms/Bug712
Open

FIX: Preserve Arrow reader fetch exceptions (#712)#718
Subrata (subrata-ms) wants to merge 5 commits into
mainfrom
subrata-ms/Bug712

Conversation

@subrata-ms

@subrata-ms Subrata (subrata-ms) commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Work Item / Issue Reference

AB#47281

GitHub Issue: #712


Summary

This pull request improves the robustness and test coverage of the cursor cleanup logic in the mssql_python package, 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:

  • Refactored the cleanup guard in batch_generator() in cursor.py to only skip cleanup if the cursor is None, closed, or has no hstmt, improving clarity and correctness.

Test coverage enhancements:

  • Added tests in test_004_cursor_arrow.py to 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:

  • Introduced a new test in test_004_cursor.py to ensure that cursor.py compiles successfully with SyntaxWarning promoted to an error, as required by Python 3.14+ (PEP 765). This helps future-proof the codebase against upcoming Python changes.
  • Added necessary imports (subprocess, sys, Path) in test_004_cursor.py to support the new compilation test.

Copilot AI lite review requested due to automatic review settings August 13, 2026 05:47
@github-actions github-actions Bot added the pr-size: medium Moderate update size label Aug 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 generator finally cleanup guard to avoid return in finally and 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.py under 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.

Comment thread tests/test_004_cursor.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-size: medium Moderate update size

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants