Opened 3 months ago
Last modified 3 months ago
#35683 closed Bug
django.utils.timezone.make_naive can underflow for timezones close to datetime.min — at Version 1
Reported by: | Liam DeVoe | Owned by: | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 5.1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
I'm a contributor over at Hypothesis. We found that saving (or retrieving?) models with aware DateTimeField values close to datetime.min can error if:
- timezone support is enabled (USE_TZ=True)
- you are using the sqlite database (presumably also any other db backend without tz aware support, if they exist?)
Explicitly:
from datetime import datetime, timezone from zoneinfo import ZoneInfo from django.utils.timezone import make_naive dt = datetime.min.replace(tzinfo=ZoneInfo(key='Africa/Addis_Ababa')) make_naive(dt, timezone.utc) # OverflowError
where make_naive is called from here. I would guess the overflow case for datetime.max is symmetric and similar as well.
I hope you'll forgive the lack of a django reproducer - I live in testing land and don't have a local django environment handy :). Hopefully the cause is clear and reproducible with vanilla django models.