Commit 7352ab2
authored
FIX: Retain original timezone in Python datetime objects (microsoft#281)
### Work Item / Issue Reference
<!--
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. microsoft#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: microsoft#213
-------------------------------------------------------------------
### Summary
<!-- 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)
<!--
### PR Title Guide
> 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)
### Contribution Guidelines
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
-->1 parent 200c35b commit 7352ab2
File tree
2 files changed
+39
-35
lines changed- mssql_python/pybind
- tests
2 files changed
+39
-35
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2805 | 2805 | | |
2806 | 2806 | | |
2807 | 2807 | | |
2808 | | - | |
2809 | 2808 | | |
2810 | 2809 | | |
2811 | 2810 | | |
| |||
3318 | 3317 | | |
3319 | 3318 | | |
3320 | 3319 | | |
3321 | | - | |
3322 | 3320 | | |
3323 | 3321 | | |
3324 | 3322 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7887 | 7887 | | |
7888 | 7888 | | |
7889 | 7889 | | |
7890 | | - | |
7891 | | - | |
7892 | | - | |
7893 | | - | |
7894 | | - | |
7895 | | - | |
| 7890 | + | |
7896 | 7891 | | |
7897 | 7892 | | |
7898 | 7893 | | |
| |||
7926 | 7921 | | |
7927 | 7922 | | |
7928 | 7923 | | |
7929 | | - | |
7930 | | - | |
7931 | | - | |
7932 | | - | |
7933 | | - | |
7934 | | - | |
| 7924 | + | |
7935 | 7925 | | |
7936 | 7926 | | |
7937 | 7927 | | |
| |||
7986 | 7976 | | |
7987 | 7977 | | |
7988 | 7978 | | |
7989 | | - | |
7990 | | - | |
7991 | | - | |
7992 | | - | |
7993 | | - | |
7994 | | - | |
| 7979 | + | |
7995 | 7980 | | |
7996 | 7981 | | |
7997 | 7982 | | |
| |||
8068 | 8053 | | |
8069 | 8054 | | |
8070 | 8055 | | |
8071 | | - | |
8072 | | - | |
8073 | | - | |
8074 | | - | |
8075 | | - | |
8076 | | - | |
8077 | | - | |
8078 | | - | |
8079 | | - | |
8080 | | - | |
8081 | | - | |
| 8056 | + | |
8082 | 8057 | | |
8083 | 8058 | | |
8084 | 8059 | | |
| |||
8144 | 8119 | | |
8145 | 8120 | | |
8146 | 8121 | | |
8147 | | - | |
8148 | | - | |
8149 | | - | |
8150 | | - | |
| 8122 | + | |
8151 | 8123 | | |
8152 | 8124 | | |
8153 | 8125 | | |
| 8126 | + | |
| 8127 | + | |
| 8128 | + | |
| 8129 | + | |
| 8130 | + | |
| 8131 | + | |
| 8132 | + | |
| 8133 | + | |
| 8134 | + | |
| 8135 | + | |
| 8136 | + | |
| 8137 | + | |
| 8138 | + | |
| 8139 | + | |
| 8140 | + | |
| 8141 | + | |
| 8142 | + | |
| 8143 | + | |
| 8144 | + | |
| 8145 | + | |
| 8146 | + | |
| 8147 | + | |
| 8148 | + | |
| 8149 | + | |
| 8150 | + | |
| 8151 | + | |
| 8152 | + | |
| 8153 | + | |
| 8154 | + | |
| 8155 | + | |
| 8156 | + | |
| 8157 | + | |
| 8158 | + | |
| 8159 | + | |
8154 | 8160 | | |
8155 | 8161 | | |
8156 | 8162 | | |
| |||
0 commit comments