fix: Return UTC-aware datetimes from unmarshalling#809
Open
abrookins wants to merge 4 commits intoredis:mainfrom
Open
fix: Return UTC-aware datetimes from unmarshalling#809abrookins wants to merge 4 commits intoredis:mainfrom
abrookins wants to merge 4 commits intoredis:mainfrom
Conversation
Previously, datetime fields were unmarshalled using datetime.fromtimestamp(value) which returns a naive datetime in the server's local timezone. This caused: - Non-deterministic behavior depending on server timezone - Inability to compare retrieved datetimes with timezone-aware datetimes - Time jumps around daylight savings transitions This fix changes unmarshalling to use datetime.fromtimestamp(value, timezone.utc) which returns a UTC-aware datetime. This follows the standard ORM pattern of storing UTC and returning UTC-aware datetimes. BREAKING CHANGE: Retrieved datetime fields are now UTC-aware instead of naive local time. Code that compared retrieved datetimes with naive datetimes will need to either: 1. Make the comparison datetime UTC-aware, or 2. Use .timestamp() for comparison Fixes redis#807
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.
Summary
Fixes #807 - Unmarshalled datetime fields are now UTC-aware instead of naive local time.
Problem
Previously, datetime fields were unmarshalled using
datetime.fromtimestamp(value)which returns a naive datetime in the server's local timezone. This caused:Solution
Changed unmarshalling to use
datetime.fromtimestamp(value, datetime.timezone.utc)which returns a UTC-aware datetime. This follows the standard ORM pattern of storing UTC and returning UTC-aware datetimes.Breaking Change
Retrieved datetime fields are now UTC-aware instead of naive local time. Code that compared retrieved datetimes with naive datetimes will need to either:
.timestamp()for comparisonTests
Added new tests for timezone-aware datetime handling and updated existing tests to work with the new behavior.
Co-authored by Augment Code