Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#19708 closed Bug (fixed)

django.utils.timezone.override helper may raise AttributeError

Reported by: Rafal Stozek Owned by: Aymeric Augustin
Component: Uncategorized Version: 1.4
Severity: Normal Keywords: timezone utils
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Here's a simple test case:

>>> from django.utils import timezone
>>> timezone.deactivate()
>>> with timezone.override(None):
...     pass
... 
Traceback (most recent call last):
  File "<console>", line 2, in <module>
  File "/django/django/utils/timezone.py", line 204, in __exit__
    del _active.value
AttributeError: value

This happens in __exit__() method of override helper when current timezone is deactivated and we try to use override with None argument (which is valid - it means that we want to deactivate current timezone).

Change History (6)

comment:1 by Rafal Stozek, 12 years ago

Status: newassigned

comment:2 by Aymeric Augustin, 12 years ago

Owner: changed from Rafal Stozek to Aymeric Augustin
Triage Stage: UnreviewedAccepted

The fix looks good.

I'm less convinced by the setUp and tearDown methods you added. As far as I can tell wrapping the whole test in:

try:
    ...
finally:
    deactivate()

would suffice.

comment:3 by Aymeric Augustin, 12 years ago

Also -- the tests in the PR won't run without pytz.

I'll modify the tests and commit your fix.

Version 0, edited 12 years ago by Aymeric Augustin (next)

comment:4 by Aymeric Augustin <aymeric.augustin@…>, 12 years ago

Resolution: fixed
Status: assignedclosed

In db49b6d2b298bc53b55df9ee7cf80e6492d3116b:

[1.5.x] Fixed #19708 -- Exception in timezone.override(None).

Thanks rafales.

Backport of 9a4a1ce.

comment:5 by Aymeric Augustin <aymeric.augustin@…>, 12 years ago

In 9a4a1ce323237d0aadafbddcd270c47be251bac2:

Fixed #19708 -- Exception in timezone.override(None).

Thanks rafales.

comment:6 by Aymeric Augustin <aymeric.augustin@…>, 12 years ago

In db49b6d2b298bc53b55df9ee7cf80e6492d3116b:

[1.5.x] Fixed #19708 -- Exception in timezone.override(None).

Thanks rafales.

Backport of 9a4a1ce.

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