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 AI review requested due to automatic review settings October 7, 2025 05:43
Copy link
Contributor

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
@github-actions
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
gargsaumya added a commit that referenced this pull request Nov 3, 2025
<!--
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#29184](https://sqlclientdrivers.visualstudio.com/mssql-python/_workitems/edit/39184)
<!-- External contributors: GitHub Issue -->
> GitHub Issue: #213

-------------------------------------------------------------------
<!-- Insert your summary of changes below. Minimum 10 characters
required. -->

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]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L2808)
[[2]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L3321)

**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]](diffhunk://#diff-82594712308ff34afa8b067af67db231e9a1372ef474da3db121e14e4d418f69L7890-R7890)
[[2]](diffhunk://#diff-82594712308ff34afa8b067af67db231e9a1372ef474da3db121e14e4d418f69L7929-R7924)
[[3]](diffhunk://#diff-82594712308ff34afa8b067af67db231e9a1372ef474da3db121e14e4d418f69L7989-R7979)
[[4]](diffhunk://#diff-82594712308ff34afa8b067af67db231e9a1372ef474da3db121e14e4d418f69L8071-R8056)
[[5]](diffhunk://#diff-82594712308ff34afa8b067af67db231e9a1372ef474da3db121e14e4d418f69L8147-R8122)
<!--

> For feature requests
FEAT: (short-description)

> For non-feature requests like test case updates, config updates ,
dependency updates etc
CHORE: (short-description)

> For Fix requests
FIX: (short-description)

> For doc update requests
DOC: (short-description)

> For Formatting, indentation, or styling update
STYLE: (short-description)

> For Refactor, without any feature changes
REFACTOR: (short-description)

> For release related changes, without any feature changes
RELEASE: #<RELEASE_VERSION> (short-description)

External contributors:
- Create a GitHub issue first:
https://github.com/microsoft/mssql-python/issues/new
- Link the GitHub issue in the "GitHub Issue" section above
- Follow the PR title format and provide a meaningful summary

mssql-python maintainers:
- Create an ADO Work Item following internal processes
- Link the ADO Work Item in the "ADO Work Item" section above
- Follow the PR title format and provide a meaningful summary
-->
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.

5 participants