#35683: django.utils.timezone.make_naive can underflow for timezones close to datetime.min -------------------------------+-------------------------------------- Reporter: tybug | Owner: (none) Type: Bug | Status: new Component: Uncategorized | Version: 5.1 Severity: Normal | Resolution: Keywords: | Triage Stage: Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------+-------------------------------------- Description changed by tybug:
Old description: > I'm a contributor over at [https://github.com/HypothesisWorks/hypothesis > Hypothesis]. > [https://github.com/HypothesisWorks/hypothesis/pull/4086#issuecomment-2290742590 > 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 > [https://github.com/django/django/blob/a57596e443ecb67140e1a9fc0f0e87446b2d0174/django/db/backends/sqlite3/operations.py#L269 > 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. New description: I'm a contributor over at [https://github.com/HypothesisWorks/hypothesis Hypothesis]. [https://github.com/HypothesisWorks/hypothesis/pull/4086#issuecomment-2290742590 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 [https://github.com/django/django/blob/a57596e443ecb67140e1a9fc0f0e87446b2d0174/django/db/backends/sqlite3/operations.py#L269 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. -- -- Ticket URL: <https://code.djangoproject.com/ticket/35683#comment:1> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/0107019157e86547-ec4641ff-2b99-4b8a-ad47-e16174b0048c-000000%40eu-central-1.amazonses.com.