FIX: honor database time zone when adapting datetimes - #552
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. |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
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. |
|
Fixed the failing timezone lookup conversion and added coverage for it. The focused tests pass locally. Could you rerun Azure? |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/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
|
There was a problem hiding this comment.
🟡 Changes recommended
Constant offsets produce incorrect SQL conversions for database time zones observing daylight saving time.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
| connection_offset = self._get_utcoffset(connection_tzname) if connection_tzname else 0 | ||
| return self._get_utcoffset(tzname) - connection_offset |
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