Skip to content

Conversation

bewithgaurav
Copy link
Collaborator

@bewithgaurav bewithgaurav commented Oct 1, 2025

Work Item / Issue Reference

AB#39062


Summary

This pull request updates the package to version 0.13.0 and revises the release notes to highlight new features and critical stability improvements. The most important changes are grouped below:

Version update:

  • Updated the package version from 0.12.0 to 0.13.0 in setup.py to reflect the latest release.

Release notes and feature enhancements (in PyPI_Description.md):

  • Added support for streaming large values (NVARCHAR/VARCHAR/VARBINARY(MAX)) in executemany() with automatic Data-At-Execution detection and fallback, enabling efficient handling of massive datasets.
  • Improved batch operations with complete support for UNIQUEIDENTIFIER and DATETIMEOFFSET in executemany(), including automatic type inference for bulk inserts of UUIDs and timezone-aware datetimes.
  • Enhanced cursor reliability by improving cursor.rowcount accuracy for all fetch operations, including proper handling of empty result sets and consistent behavior for SELECT, INSERT, and UPDATE.
  • Addressed critical stability issues by resolving memory leaks, fixing resource cleanup to prevent segmentation faults during Python shutdown, and correcting type inference bugs in batch operations.

@Copilot Copilot AI review requested due to automatic review settings October 1, 2025 07:30
Copy link
Contributor

@Copilot Copilot AI left a comment

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 updates the mssql-python package to version 0.13.0, incorporating significant enhancements to batch operations, streaming capabilities, and stability improvements. The release focuses on better handling of complex data types and large objects while addressing critical memory management issues.

Key changes:

  • Version bump from 0.12.0 to 0.13.0
  • Updated release notes to highlight new streaming capabilities for large values
  • Enhanced batch operation support for complex data types with automatic type inference

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
setup.py Updates package version from 0.12.0 to 0.13.0
PyPI_Description.md Revises release notes to document v0.13.0 features including streaming support, enhanced batch operations, and stability fixes

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@github-actions github-actions bot added the pr-size: small Minimal code update label Oct 1, 2025
gargsaumya
gargsaumya previously approved these changes Oct 1, 2025
Copy link
Contributor

@gargsaumya gargsaumya left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

github-actions bot commented Oct 1, 2025

📊 Code Coverage Report

🔥 Diff Coverage

100%


🎯 Overall Coverage

74%


📈 Total Lines Covered: 4182 out of 5606
📁 Project: mssql-python


Diff Coverage

Diff: main...HEAD, staged and unstaged changes

  • mssql_python/pybind/ddbc_bindings.cpp (100%)

Summary

  • Total: 5 lines
  • Missing: 0 lines
  • Coverage: 100%

📋 Files Needing Attention

📉 Files with overall lowest coverage (click to expand)
mssql_python.pybind.connection.connection.cpp: 67.6%
mssql_python.ddbc_bindings.py: 68.5%
mssql_python.pybind.ddbc_bindings.cpp: 69.3%
mssql_python.cursor.py: 79.6%
mssql_python.connection.py: 81.7%
mssql_python.helpers.py: 84.7%
mssql_python.auth.py: 85.3%
mssql_python.type.py: 86.8%
mssql_python.pooling.py: 88.8%
mssql_python.exceptions.py: 90.4%

🔗 Quick Links

⚙️ Build Summary 📋 Coverage Details

View Azure DevOps Build

Browse Full Coverage Report

sumitmsft
sumitmsft previously approved these changes Oct 1, 2025
@bewithgaurav bewithgaurav dismissed stale reviews from sumitmsft and gargsaumya via 8c727fd October 1, 2025 10:30
### Work Item / Issue Reference  
<!-- 
IMPORTANT: Please follow the PR template guidelines below.
For mssql-python maintainers: Insert your ADO Work Item ID below (e.g.
AB#37452)
For external contributors: Insert Github Issue number below (e.g. #149)
Only one reference is required - either GitHub issue OR ADO Work Item.
-->

<!-- mssql-python maintainers: ADO Work Item -->
>
[AB#39063](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/39063)

-------------------------------------------------------------------
### Summary   
<!-- Insert your summary of changes below. Minimum 10 characters
required. -->
## Problem
Pytest test suite (335+ tests) was crashing on exit with:
```
Fatal Python error: _Py_GetConfig: the function must be called with the GIL held, 
after Python initialization and before Python finalization, but the GIL is released
```

The crash occurred **after all tests passed**, during Python shutdown on
Windows x64 and macOS.

## Root Cause
Static `pybind11::module_` and `pybind11::object` instances in
`BindParameterArray()` function (lines 2072-2073) were being destroyed
during C++ static destruction phase, which happens **after** Python has
released the GIL and begun finalization.

When the destructors called `Py_XDECREF`, Python's `_Py_GetConfig()` was
invoked without the GIL, causing the fatal error.

```cpp
// OLD CODE - Problematic static objects
static py::module_ uuid_mod = py::module_::import("uuid");
static py::object uuid_class = uuid_mod.attr("UUID");
```

## Solution
Moved UUID class caching to module initialization level using a helper
function. This ensures the Python object lifecycle is managed within
pybind11's module context, avoiding destructor calls during
finalization.

```cpp
// NEW CODE - Module-level cached helper
py::object uuid_class = py::module_::import("mssql_python.ddbc_bindings").attr("_get_uuid_class")();
```

The `_get_uuid_class()` helper is defined at module initialization and
maintains a static cache that lives for the module's lifetime, properly
integrated with pybind11's lifecycle management.

## Testing
- ✅ Full test suite (335+ tests) now completes without crash on macOS
- ✅ Exit code 0 after pytest completion
- ✅ No functionality changes - UUID parameter binding works identically

## Impact
- **Platforms affected**: Windows x64, macOS (all platforms with the
issue)
- **Risk**: Low - surgical fix, no behavioral changes
- **Files changed**: 1 file, ~15 lines added/modified
Copy link
Contributor

@gargsaumya gargsaumya left a comment

Choose a reason for hiding this comment

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

LGTM

@bewithgaurav bewithgaurav merged commit 49a04c3 into main Oct 3, 2025
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-size: small Minimal code update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants