Opened 10 years ago
Closed 10 years ago
#26015 closed Bug (fixed)
sitemap view can raise UnboundLocalError
| Reported by: | Keryn Knight | Owned by: | Andrew Kuchev |
|---|---|---|---|
| Component: | contrib.sitemaps | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | django@… | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
Given the following urlconf definition:
from django.contrib.sitemaps.views import sitemap
url(r'^sitemap.xml$', sitemap, {'sitemaps': {}}, name='is_broken')
any attempt to load that URL will raise:
UnboundLocalError at /sitemap.xml local variable 'site' referenced before assignment
because if hasattr(site, 'latest_lastmod') attempts to access site which is only ever set if for site in maps yields at least one iteration.
It should instead return an empty urlset, or possibly raise an Http404 with an appropriate debug message.
Change History (8)
comment:1 by , 10 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 10 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:3 by , 10 years ago
| Owner: | removed |
|---|---|
| Status: | assigned → new |
comment:4 by , 10 years ago
| Easy pickings: | set |
|---|
While the related ticket is resolved and this should be fixed, it would be useful to add a regression test for this case.
comment:5 by , 10 years ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:6 by , 10 years ago
| Has patch: | set |
|---|
I've added a PR with regression test: https://github.com/django/django/pull/6033
comment:8 by , 10 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
The fix proposed for #25989 should also fix this ticket.