Skip to content

fix: Return UTC-aware datetimes from unmarshalling#809

Open
abrookins wants to merge 4 commits intoredis:mainfrom
abrookins:fix/datetime-timezone-aware
Open

fix: Return UTC-aware datetimes from unmarshalling#809
abrookins wants to merge 4 commits intoredis:mainfrom
abrookins:fix/datetime-timezone-aware

Conversation

@abrookins
Copy link
Collaborator

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:

  • Non-deterministic behavior depending on server timezone
  • Inability to compare retrieved datetimes with timezone-aware datetimes
  • Time jumps around daylight savings transitions

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:

  1. Make the comparison datetime UTC-aware, or
  2. Use .timestamp() for comparison

Tests

Added new tests for timezone-aware datetime handling and updated existing tests to work with the new behavior.


Co-authored by Augment Code

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unmarshalled Datetime fields are naive

1 participant