-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Open
Labels
Description
Description
In src/sentry/search/utils.py, line 220, date.replace(tzinfo=timezone.utc) discards its return value:
def parse_iso_timestamp(value: str) -> datetime:
date = datetime.fromisoformat(value.replace("Z", "+00:00"))
# Values with no timezone info will default to UTC
if not date.tzinfo:
date.replace(tzinfo=timezone.utc) # ← return value discarded
# Convert to UTC
return datetime.fromtimestamp(date.timestamp(), tz=timezone.utc)datetime is immutable — replace() returns a new object and does not mutate the original. The fix is:
date = date.replace(tzinfo=timezone.utc)Note: line 264 in the same file uses the correct pattern:
result = datetime.strptime(value, DATE_FORMAT).replace(tzinfo=timezone.utc)Impact
When parse_iso_timestamp() receives a timezone-naive ISO 8601 string (e.g., "2026-03-12T10:30:00"), the date object remains naive. date.timestamp() on a naive datetime uses the server's local timezone, not UTC.
- Servers running in UTC: no visible impact (coincidentally correct).
- Non-UTC servers (local dev, on-premise): search queries with timezone-naive timestamps will be offset by the server's UTC difference (e.g., ±9 hours for JST).
This function is called via parse_datetime_string() from:
- API
start/endparameter parsing (api/utils.py) - Event search date filters (
api/event_search.py) - Metrics API transformations
- Trend analysis, root cause analysis, statistical detectors
Fix
One-line change:
- date.replace(tzinfo=timezone.utc)
+ date = date.replace(tzinfo=timezone.utc)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Projects
Status
Waiting for: Support