Django 4.0, released on December 7, 2021, makes Python’s zoneinfo its default time-zone implementation. Applications using Django’s make_aware() helper to attach a time zone to a value without an offset need to check one argument: is_dst has no effect when the helper receives a zoneinfo time zone. Code that relied on that argument to resolve daylight-saving choices needs review even if the call still runs. [S1][S4][S5]

The release notes do not call for rewriting every time-zone operation. Django says selecting the current time zone, converting date/time values in forms and templates, and working with time-zone-aware values in UTC are unaffected. The audit targets code using non-UTC zones and pytz’s localize() or normalize() methods, because pytz and zoneinfo are not fully equivalent. In make_aware(), the 4.0 source still passes is_dst to localize() when it receives a pytz time-zone object. With zoneinfo, it instead attaches the supplied time zone to a naive value—one without a defined time-zone offset. [S4][S5][S3]

Local times can be ambiguous or nonexistent when the clocks change, Django’s guide warns. The make_aware() source cautions that its non-pytz path may be wrong around those changes; that path does not check for ambiguous or nonexistent times. Forms provide a different safeguard: with time-zone support enabled, Django interprets entered values in the current time zone and rejects converted values that are ambiguous or nonexistent because of a transition. A useful migration test would exercise direct make_aware() calls as well as form entry, checking the resulting offsets rather than only whether a call returns. For choosing an offset during a transition, the guide points to the datetime value’s fold attribute in the zoneinfo documentation. [S3][S5]

Teams can retain pytz by setting USE_DEPRECATED_PYTZ = True during the 4.x release cycle. The release notes schedule removal of that setting and pytz support for Django 5.0, not 4.0. This setting does not turn a manually supplied zoneinfo object into a pytz object. The make_aware() implementation chooses its conversion path from the actual time-zone object, so callers that supply one explicitly still need inspection. [S4][S5]

USE_TZ controls a different choice: whether time-zone support is enabled at all. Django 4.0 does not change its framework default from False to True; the release notes schedule that change for Django 5.0. Yet the settings file generated by django-admin startproject has included USE_TZ = True since Django 1.4. An existing project may therefore already have time-zone support enabled when its default implementation changes to zoneinfo. [S3][S4]

Source documents

  1. Django 4.0 releasedhttps://www.djangoproject.com/weblog/2021/dec/07/django-40-released/
  2. Django 4.0 release notes — release commithttps://raw.githubusercontent.com/django/django/67d0c4644acfd7707be4a31e8976f865509b09ac/docs/releases/4.0.txt
  3. Django 4.0 time-zone documentation — release commithttps://raw.githubusercontent.com/django/django/67d0c4644acfd7707be4a31e8976f865509b09ac/docs/topics/i18n/timezones.txt
  4. Django 4.0 django.utils.timezone implementation — release commithttps://raw.githubusercontent.com/django/django/67d0c4644acfd7707be4a31e8976f865509b09ac/django/utils/timezone.py