From 69a20afe29cc8d2d64415294cecd49b30f9b7d50 Mon Sep 17 00:00:00 2001 From: Gaurav Sharma Date: Wed, 1 Oct 2025 12:58:58 +0530 Subject: [PATCH 1/5] RELEASE: 0.13.0 --- PyPI_Description.md | 10 +++++----- setup.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/PyPI_Description.md b/PyPI_Description.md index 9c6c81f8..f982a141 100644 --- a/PyPI_Description.md +++ b/PyPI_Description.md @@ -39,12 +39,12 @@ PyBind11 provides: We are currently in **Public Preview**. -## What's new in v0.12.0 +## What's new in v0.13.0 -- **Complex Data Type Support:** Added native support for DATETIMEOFFSET and UNIQUEIDENTIFIER data types with full round-trip handling, enabling seamless integration with Python's timezone-aware `datetime` objects and `uuid.UUID` types. -- **Support for monetary or currency values data types:** Extended MONEY and SMALLMONEY support to `executemany` operations with proper NULL handling and decimal conversion for improved bulk financial data processing. -- **Improved Database Metadata API:** Added `getinfo()` method with enhanced ODBC metadata retrieval, allowing users to query driver/data source information using ODBC info types. -- **Data Processing Optimizations:** Removed aggressive datetime parsing to prevent incorrect type conversions and improve data integrity across diverse datetime formats and string data. +- **Enhanced Batch Operations:** Complete support for UNIQUEIDENTIFIER and DATETIMEOFFSET in `executemany()` operations with automatic type inference, enabling efficient bulk inserts of complex data types including UUIDs and timezone-aware datetimes. +- **Streaming Large Values:** Robust handling of large objects (NVARCHAR/VARCHAR/VARBINARY(MAX)) in `executemany()` with automatic Data-At-Execution detection and fallback, supporting streaming inserts and fetches for massive datasets. +- **Improved Cursor Reliability:** Enhanced `cursor.rowcount` accuracy across all fetch operations, including proper handling of empty result sets and consistent behavior for SELECT, INSERT, and UPDATE operations. +- **Critical Stability Fixes:** Resolved memory leaks with secure token buffer handling, fixed resource cleanup to prevent segmentation faults during Python shutdown, and corrected type inference bugs in batch operations. For more information, please visit the project link on Github: https://github.com/microsoft/mssql-python diff --git a/setup.py b/setup.py index 8f9be2f8..7bd6dcaf 100644 --- a/setup.py +++ b/setup.py @@ -83,7 +83,7 @@ def finalize_options(self): setup( name='mssql-python', - version='0.12.0', + version='0.13.0', description='A Python library for interacting with Microsoft SQL Server', long_description=open('PyPI_Description.md', encoding='utf-8').read(), long_description_content_type='text/markdown', From 8c727fd6c63fb6b89b34b1f11095ac1bdd18357f Mon Sep 17 00:00:00 2001 From: Gaurav Sharma Date: Wed, 1 Oct 2025 16:00:27 +0530 Subject: [PATCH 2/5] use macOS-14 for builds --- eng/pipelines/build-whl-pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/pipelines/build-whl-pipeline.yml b/eng/pipelines/build-whl-pipeline.yml index a22edd08..1f35c908 100644 --- a/eng/pipelines/build-whl-pipeline.yml +++ b/eng/pipelines/build-whl-pipeline.yml @@ -217,7 +217,7 @@ jobs: - job: BuildMacOSWheels # Use the latest macOS image for building pool: - vmImage: 'macos-latest' + vmImage: 'macos-14' # Display name for the job in Azure DevOps UI displayName: 'Build macOS - ' strategy: From 7e652908bf845e81c70d2c097e723221f9235166 Mon Sep 17 00:00:00 2001 From: Gaurav Sharma Date: Wed, 1 Oct 2025 16:01:25 +0530 Subject: [PATCH 3/5] RELEASE: 0.13.0 --- eng/pipelines/build-whl-pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/pipelines/build-whl-pipeline.yml b/eng/pipelines/build-whl-pipeline.yml index 1f35c908..b34ce5c8 100644 --- a/eng/pipelines/build-whl-pipeline.yml +++ b/eng/pipelines/build-whl-pipeline.yml @@ -217,7 +217,7 @@ jobs: - job: BuildMacOSWheels # Use the latest macOS image for building pool: - vmImage: 'macos-14' + vmImage: 'macos-14' # Use macOS-14 for builds temporarily # Display name for the job in Azure DevOps UI displayName: 'Build macOS - ' strategy: From 50e441077c967e90447f135deca7024e851452c5 Mon Sep 17 00:00:00 2001 From: Gaurav Sharma Date: Wed, 1 Oct 2025 19:19:50 +0530 Subject: [PATCH 4/5] FIX: Static UUID variable causes pytest crash (#271) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### Work Item / Issue Reference > [AB#39063](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/39063) ------------------------------------------------------------------- ### Summary ## 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 --- mssql_python/pybind/ddbc_bindings.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mssql_python/pybind/ddbc_bindings.cpp b/mssql_python/pybind/ddbc_bindings.cpp index 13367b4c..41478797 100644 --- a/mssql_python/pybind/ddbc_bindings.cpp +++ b/mssql_python/pybind/ddbc_bindings.cpp @@ -2069,8 +2069,10 @@ SQLRETURN BindParameterArray(SQLHANDLE hStmt, SQLGUID* guidArray = AllocateParamBufferArray(tempBuffers, paramSetSize); strLenOrIndArray = AllocateParamBufferArray(tempBuffers, paramSetSize); - static py::module_ uuid_mod = py::module_::import("uuid"); - static py::object uuid_class = uuid_mod.attr("UUID"); + // Get cached UUID class from module-level helper + // This avoids static object destruction issues during Python finalization + py::object uuid_class = py::module_::import("mssql_python.ddbc_bindings").attr("_get_uuid_class")(); + for (size_t i = 0; i < paramSetSize; ++i) { const py::handle& element = columnValues[i]; std::array uuid_bytes; @@ -3903,6 +3905,14 @@ PYBIND11_MODULE(ddbc_bindings, m) { }); + // Module-level UUID class cache + // This caches the uuid.UUID class at module initialization time and keeps it alive + // for the entire module lifetime, avoiding static destructor issues during Python finalization + m.def("_get_uuid_class", []() -> py::object { + static py::object uuid_class = py::module_::import("uuid").attr("UUID"); + return uuid_class; + }, "Internal helper to get cached UUID class"); + // Add a version attribute m.attr("__version__") = "1.0.0"; From 1222e6f5e0b1412c784dede043fbb9895427f0c8 Mon Sep 17 00:00:00 2001 From: Gaurav Sharma Date: Wed, 1 Oct 2025 19:21:38 +0530 Subject: [PATCH 5/5] RELEASE: 0.13.0 --- eng/pipelines/build-whl-pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/pipelines/build-whl-pipeline.yml b/eng/pipelines/build-whl-pipeline.yml index b34ce5c8..a22edd08 100644 --- a/eng/pipelines/build-whl-pipeline.yml +++ b/eng/pipelines/build-whl-pipeline.yml @@ -217,7 +217,7 @@ jobs: - job: BuildMacOSWheels # Use the latest macOS image for building pool: - vmImage: 'macos-14' # Use macOS-14 for builds temporarily + vmImage: 'macos-latest' # Display name for the job in Azure DevOps UI displayName: 'Build macOS - ' strategy: