FIX: honor database time zone when adapting datetimes - #552
Open
Guflly (Guflly) wants to merge 3 commits into
Open
FIX: honor database time zone when adapting datetimes#552Guflly (Guflly) wants to merge 3 commits into
Guflly (Guflly) wants to merge 3 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Collaborator
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the SQL Server backend’s datetime adaptation logic to use the database connection’s configured time zone when preparing aware datetime values for persistence/query parameters, aligning write-time behavior with the existing read-time conversion path (and fixing mismatches when USE_TZ=True and the DB time zone isn’t UTC).
Changes:
- Change
DatabaseOperations.adapt_datetimefield_value()to convert aware datetimes to naive usingself.connection.timezone(instead of forcing UTC awareness). - Add a regression unit test ensuring non-UTC database time zones are honored when adapting aware datetimes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
mssql/operations.py |
Fixes datetime adaptation to use the connection’s time zone when USE_TZ=True, matching the conversion logic used on reads. |
testapp/tests/test_timezones.py |
Adds a regression test covering adaptation behavior with a non-UTC database time zone. |
Author
|
Fixed the failing timezone lookup conversion and added coverage for it. The focused tests pass locally. Could you rerun Azure? |
Collaborator
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Collaborator
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
📊 Code Coverage Report
Diff CoverageDiff: dev...HEAD, staged and unstaged changesNo lines with coverage information in this diff. 📋 Files Needing Attention📉 Files with overall lowest coverage (click to expand)- mssql/client.py: 19.5% (41 lines)
- mssql/__init__.py: 50.0% (2 lines)
- mssql/creation.py: 56.8% (74 lines)
- mssql/operations.py: 80.0% (400 lines)
- mssql/compiler.py: 82.3% (644 lines)
- mssql/functions.py: 84.1% (428 lines)
- mssql/base.py: 84.8% (514 lines)
- mssql/schema.py: 88.3% (719 lines)
- mssql/introspection.py: 90.2% (133 lines)
- mssql/features.py: 98.9% (88 lines)🔗 Quick Links
|
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uses the database connection's time zone when adapting aware datetime values and when converting datetime lookup SQL to another time zone.
Adds regressions for non-UTC parameter adaptation, cross-time-zone lookup conversion, UTC defaults, and matching time zones.
Tested with
python manage.py test testapp.tests.test_timezones.TestDatabaseOperations --noinput.Fixes #371