Skip to content

fix: Return UTC-aware datetimes from unmarshalling#809

Merged
abrookins merged 9 commits intoredis:mainfrom
abrookins:fix/datetime-timezone-aware
Mar 6, 2026
Merged

fix: Return UTC-aware datetimes from unmarshalling#809
abrookins merged 9 commits intoredis:mainfrom
abrookins:fix/datetime-timezone-aware

Conversation

@abrookins
Copy link
Collaborator

@abrookins abrookins commented Feb 24, 2026

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


Note

Medium Risk
Changes core datetime/date (de)serialization and query value normalization, which can break consumers expecting naive/local-time datetimes and may subtly affect date equality behavior across timezones.

Overview
Standardizes datetime handling to UTC. Timestamp unmarshalling now uses datetime.fromtimestamp(..., datetime.timezone.utc) so retrieved datetime values are timezone-aware, and date values are stored/query-normalized to UTC midnight to avoid timezone-dependent day shifts.

Updates numeric query value conversion to match the new UTC normalization and adjusts tests to assert UTC-aware behavior, adding explicit coverage for timezone-aware inputs and timezone-independent date round-trips/queries. Separately, the sync-code generator (make_sync.py) now post-fixes a duplicated redisvl import and runs ruff format on generated sync output to satisfy CI linting.

Written by Cursor Bugbot for commit 56d5f65. This will update automatically on new commits. Configure here.

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
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

@abrookins abrookins merged commit 72ed796 into redis:main Mar 6, 2026
17 checks passed
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