#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 , 13 years ago
| Status: | new → assigned |
|---|
comment:2 by , 13 years ago
| Owner: | changed from to |
|---|---|
| Triage Stage: | Unreviewed → 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 by , 13 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 13 years ago by (next)
comment:4 by , 13 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
Sent pull request: https://github.com/django/django/pull/689