Opened 8 years ago

Closed 8 years ago

#27322 closed Bug (wontfix)

get_default_timezone() / LocalTimezone does not handle None values

Reported by: Daniel F Moisset Owned by: nobody
Component: Utilities Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When not using pytz, django.utils.timezone.get_default_timezone() returns a django.utils.timezone.LocalTimezone instance, which appears to be based in an example in the datetime documentation at https://docs.python.org/3.5/library/datetime.html . The examples in that documentation have a bug ( http://bugs.python.org/issue28386 ), which is related to accepting sometz.dst(None) method calls. That call happens when calling some_time_instance.dst(). You can reproduce with:

>>> from django.utils import timezone
>>> tz = timezone.get_default_timezone()
>>> tz
<django.utils.timezone.LocalTimezone object at 0x7fd71280c0b8>
>>> from datetime import time
>>> t = time(8, 30, tzinfo=tz)
>>> t.dst()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/machinalis/0/django/lib/python3.5/site-packages/django/utils/timezone.py", line 112, in dst
    if self._isdst(dt):
  File "/home/machinalis/0/django/lib/python3.5/site-packages/django/utils/timezone.py", line 143, in _isdst
    return super(LocalTimezone, self)._isdst(dt)
  File "/home/machinalis/0/django/lib/python3.5/site-packages/django/utils/timezone.py", line 121, in _isdst
    tt = (dt.year, dt.month, dt.day,
AttributeError: 'NoneType' object has no attribute 'year'

The example above works ok if pytz is installed (because pytz timezone classes handle None correctly)

Change History (2)

comment:1 by Aymeric Augustin, 8 years ago

IMO the proper resolution is "just installl pytz". We were discussing making it a mandatory dependency recently. I'd rather remove that buggy code than fix it.

If someone finds pleasure in fixing this, it would be even more useful to fix it in Python's docs!

comment:2 by Tim Graham, 8 years ago

Component: UncategorizedUtilities
Resolution: wontfix
Status: newclosed

I created #27327 for requiring pytz.

Note: See TracTickets for help on using tickets.
Back to Top