#29514 closed Bug (fixed)
get_default_timezone() for UTC is no longer equivalent to timezone.utc
Reported by: | Carlton Gibson | Owned by: | |
---|---|---|---|
Component: | Utilities | Version: | 2.1 |
Severity: | Release blocker | Keywords: | |
Cc: | Sergey Fedoseev | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
CI testing on Django REST Framework revealed a change in behaviour in timezone.get_default_timezone()
.
The essence is:
with override_settings(USE_TZ=True, TIME_ZONE='UTC'): self.assertIs(timezone.get_default_timezone(), timezone.utc)
This passes fails 2.0.x and (currently) fails on 2.1/master.
Regression in 27ca5ce19f5f184018a61611c1bc319113b1d107.
Change History (9)
comment:1 by , 6 years ago
Has patch: | set |
---|
comment:2 by , 6 years ago
Cc: | added |
---|---|
Summary: | Regression in get_default_timezone() → get_default_timezone() for UTC is no longer equivalent to timezone.utc |
comment:3 by , 6 years ago
Triage Stage: | Unreviewed → Accepted |
---|
The issue is also present anywhere a timezone is constructed with pytz.timezone()
, e.g. timezone.activate():
from django.conf import settings settings.configure(USE_TZ=True) from django.utils.timezone import get_current_timezone, utc from django.utils import timezone timezone.activate('UTC') get_current_timezone() is utc # False in Django 2.1, True in older versions
If we accept the proposed patch, I'd think we would also want to fix the issue there, and perhaps add a backwards incompatible release note for anyone using pytz.timezone()
in their code. It might be better to reconsider the original patch.
comment:4 by , 6 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
I'm going to (temporarily) deassign myself here, as I will be unable to work on this for the next week. Happy to pick it up if it's still pending after that.
comment:7 by , 6 years ago
Just for information:
While investing, I noticed that pytz.utc is described as "Optimized UTC implementation." yet the offending commit in Django says "Used datetime.timezone.utc instead of pytz.utc for better performance."
The performance improvement basically comes from datetime being implemented in C completely, while using pytz.utc
calls into Python code (at least) 2 times (for
utcoffset
/dst
).
I'm not sure. It seems reasonable to fix the problem but having
get_default_timezone()
return a different type for a one-off case might lead to some issue.While investing, I noticed that
pytz.utc
is described as "Optimized UTC implementation." yet the offending commit in Django says "Used datetime.timezone.utc instead of pytz.utc for better performance."