-
Notifications
You must be signed in to change notification settings - Fork 25
FIX: Retain original timezone in Python datetime objects #281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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.
📊 Code Coverage Report
Diff CoverageDiff: main...HEAD, staged and unstaged changesNo 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
|
f9ee19d
to
76ce14a
Compare
Work Item / Issue Reference
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 Pythondatetime
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:
datetimeoffset
values to UTC inSQLGetData_wrap
andFetchBatchData
, so Python datetime objects retain their original timezone info. [1] [2]Test suite updates:
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]