FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

FIX: Setinputsizes() SQL_DECIMAL crash by jahnvi480 · Pull Request #519 · microsoft/mssql-python · GitHub

FIX: Setinputsizes() SQL_DECIMAL crash - #519

Merged
Jahnvi Thakkar (jahnvi480) merged 11 commits into
mainfrom
jahnvi/setinputsize_with_decimal
Apr 21, 2026
Merged

FIX: Setinputsizes() SQL_DECIMAL crash#519
Jahnvi Thakkar (jahnvi480) merged 11 commits into
mainfrom
jahnvi/setinputsize_with_decimal

Conversation

Copy link
Copy Markdown
Contributor

Work Item / Issue Reference

AB#53990

GitHub Issue: #503


Summary

This pull request improves the handling of Python Decimal values when binding to SQL DECIMAL and NUMERIC types, especially when using setinputsizes and executemany. It fixes a runtime error by ensuring Decimal objects are converted to strings for proper binding, and adds comprehensive tests to verify this behavior.

Decimal binding and conversion improvements:

  • Changed the mapping for SQL DECIMAL and NUMERIC types to use SQL_C_CHAR instead of SQL_C_NUMERIC in _get_c_type_for_sql_type, enabling string-based binding for decimals.
  • Updated parameter handling in _create_parameter_types_list and executemany to convert Python Decimal objects to strings when binding to SQL DECIMAL or NUMERIC columns.

Testing enhancements:

  • Added new tests in test_004_cursor.py to verify that setinputsizes with SQL_DECIMAL and SQL_NUMERIC accepts Python Decimal values, works with both executemany and execute, and correctly handles NULL values.

Copilot AI review requested due to automatic review settings April 14, 2026 07:35

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR fixes a crash when binding Python Decimal values to SQL DECIMAL/NUMERIC using setinputsizes() (notably with executemany) by switching to string-based binding and adding regression tests.

Changes:

  • Map SQL DECIMAL/NUMERIC to SQL_C_CHAR for C-type binding and convert Python Decimal values to strings during parameter processing.
  • Update executemany preprocessing to convert Decimal values when SQL type is DECIMAL/NUMERIC.
  • Add new cursor tests covering setinputsizes() + SQL_DECIMAL/SQL_NUMERIC with executemany, execute, and NULL.

Reviewed changes

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

File Description
mssql_python/cursor.py Switches DECIMAL/NUMERIC binding to SQL_C_CHAR and adds Decimal-to-string conversions in parameter handling paths.
tests/test_004_cursor.py Adds regression tests validating Decimal binding via setinputsizes() for execute/executemany and NULL handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread mssql_python/cursor.py Outdated
Comment thread mssql_python/cursor.py
Comment thread tests/test_004_cursor.py Outdated

github-actions Bot commented Apr 14, 2026
edited
Loading

Copy link
Copy Markdown

📊 Code Coverage Report

🔥 Diff Coverage

100%


🎯 Overall Coverage

79%


📈 Total Lines Covered: 6707 out of 8458
📁 Project: mssql-python


Diff Coverage

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

  • mssql_python/cursor.py (100%)

Summary

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

📋 Files Needing Attention

📉 Files with overall lowest coverage (click to expand)
mssql_python.pybind.logger_bridge.cpp: 59.2%
mssql_python.pybind.ddbc_bindings.h: 67.8%
mssql_python.row.py: 70.5%
mssql_python.pybind.logger_bridge.hpp: 70.8%
mssql_python.pybind.ddbc_bindings.cpp: 74.5%
mssql_python.pybind.connection.connection.cpp: 75.8%
mssql_python.__init__.py: 77.3%
mssql_python.ddbc_bindings.py: 79.6%
mssql_python.pybind.connection.connection_pool.cpp: 79.6%
mssql_python.connection.py: 85.2%

🔗 Quick Links

⚙️ Build Summary 📋 Coverage Details

View Azure DevOps Build

Browse Full Coverage Report

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

core fix lgtm, have added some commenst around tests, suggestions to improve code coverage and a possible unrelated corner case in this path
will await responses

Comment thread mssql_python/cursor.py
Comment thread mssql_python/cursor.py
Comment thread tests/test_004_cursor.py
Comment thread mssql_python/cursor.py Outdated
Jahnvi Thakkar (jahnvi480) merged commit ed33bc5 into main Apr 21, 2026
31 checks passed
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

Labels

pr-size: medium Moderate update size

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL