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 Initial Version
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
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 have half an expectation that this will be a wontfix, but I figured I'd give a heads up here. 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.