Skip to content

Conversation

gargsaumya
Copy link
Contributor

@gargsaumya gargsaumya commented Oct 7, 2025

Work Item / Issue Reference

AB#39184

GitHub Issue: #213


Summary

This pull request updates how datetimeoffset values are handled when reading from SQL Server in the Python bindings. The main change is to preserve the original timezone information in returned Python datetime objects, instead of always converting them to UTC. Correspondingly, the test suite has been updated to compare datetimes with their original timezone rather than converting to UTC for assertions.

Datetimeoffset handling improvements:

  • Removed forced conversion of datetimeoffset values to UTC in SQLGetData_wrap and FetchBatchData, so Python datetime objects retain their original timezone info. [1] [2]

Test suite updates:

  • Updated all relevant tests in tests/test_004_cursor.py to compare datetimes directly, preserving timezone information, instead of converting to UTC for equality checks. This affects tests for read/write, max/min offsets, DST transitions, executemany, and extreme offsets. [1] [2] [3] [4] [5]

@Copilot Copilot AI review requested due to automatic review settings October 7, 2025 05:43
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 pull request fixes the handling of datetimeoffset values in Python bindings to retain original timezone information instead of converting to UTC. The change allows Python datetime objects to preserve their original timezone when reading from SQL Server.

  • Removed forced UTC conversion in C++ datetime handling code
  • Updated test suite to compare datetimes directly with preserved timezone information
  • Simplified test assertions by removing UTC conversion and microsecond rounding logic

Reviewed Changes

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

File Description
mssql_python/pybind/ddbc_bindings.cpp Removed UTC conversion calls in SQLGetData_wrap and FetchBatchData functions
tests/test_004_cursor.py Updated datetimeoffset tests to compare datetime objects directly instead of converting to UTC

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 7, 2025
subrata-ms
subrata-ms previously approved these changes Oct 7, 2025
Copy link

github-actions bot commented Oct 8, 2025

📊 Code Coverage Report

🔥 Diff Coverage

100%


🎯 Overall Coverage

74%


📈 Total Lines Covered: 4186 out of 5610
📁 Project: mssql-python


Diff Coverage

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

No lines with coverage information in this diff.


📋 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.7%
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: 87.5%
mssql_python.exceptions.py: 90.4%

🔗 Quick Links

⚙️ Build Summary 📋 Coverage Details

View Azure DevOps Build

Browse Full Coverage Report

@gargsaumya gargsaumya merged commit 7352ab2 into main Oct 13, 2025
21 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.

4 participants