Update all datetime/timezone usage to avoid deprecated functionality.
Review Request #13429 — Created Nov. 22, 2023 and submitted — Latest diff uploaded
Django has deprecated
django.utils.timezone.utc
in favor of
datetime.timezone.utc
. The rest of thedjango.utils.timezone
methods
are still supported. Furthermore,datetime.timezone.utc
cannot be
directly imported, and must be accessed throughdatetime.timezone
.This leaves two possible importable targets named
datetime
(both
datetime
anddatetime.datetime
) and namedtimezone
(datetime.timezone
anddjango.utils.timezone
), all of which are
relevant.In an effort to keep things sane and consistent, the codebase now
imports the top-leveldatetime
(accessing everything as a direct
property access of that) anddjango.utils.timezone
astimezone
in
all affected modules. We may opt to go this route with all new Django
code going forward.With this change, all datetime-related warnings in unit tests have been
removed.
All unit tests pass.
Diff Revision 1
This is not the most recent revision of the diff. The latest diff is revision 2. See what's changed.
Commits
djblets/db/tests/test_modification_timestamp_field.py |
---|
djblets/privacy/tests/test_base_consent_requirement.py |
---|
djblets/privacy/tests/test_consent_data.py |
---|
djblets/privacy/tests/test_consent_tracker.py |
---|
djblets/util/dates.py |
---|
djblets/util/tests/test_dates.py |
---|
djblets/webapi/tests/test_fields.py |
---|