Code

Opened 15 months ago

Closed 15 months ago

Last modified 14 months ago

#19708 closed Bug (fixed)

django.utils.timezone.override helper may raise AttributeError

Reported by: rafales Owned by: aaugustin
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).

Attachments (0)

Change History (6)

comment:1 Changed 15 months ago by rafales

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Status changed from new to assigned

comment:2 Changed 15 months ago by aaugustin

  • Owner changed from rafales to aaugustin
  • Triage Stage changed from Unreviewed to Accepted

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 Changed 15 months ago by aaugustin

The tests in the PR won't run without pytz. (EDIT: in fact, they do, but there's a typo: TIMEZONE vs. TIME_ZONE).

I'll modify the tests and commit your fix.

Last edited 15 months ago by aaugustin (previous) (diff)

comment:4 Changed 15 months ago by Aymeric Augustin <aymeric.augustin@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In db49b6d2b298bc53b55df9ee7cf80e6492d3116b:

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

Thanks rafales.

Backport of 9a4a1ce.

comment:5 Changed 15 months ago by Aymeric Augustin <aymeric.augustin@…>

In 9a4a1ce323237d0aadafbddcd270c47be251bac2:

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

Thanks rafales.

comment:6 Changed 14 months ago by Aymeric Augustin <aymeric.augustin@…>

In db49b6d2b298bc53b55df9ee7cf80e6492d3116b:

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

Thanks rafales.

Backport of 9a4a1ce.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.