Opened 10 years ago
Closed 10 years ago
#26440 closed Cleanup/optimization (fixed)
Add check that all items in url patterns are url instances
| Reported by: | Alasdair Nicol | Owned by: | Burhan Khalid |
|---|---|---|---|
| Component: | Core (System checks) | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
If you include a tuple instead of a url() instance in your urlpatterns, the checks framework throws an error which isn't very helpful.
urlpatterns = ['', # leading string might be left by users converting from patterns() in earlier Django versions
(r'^$', my_view),
url(r'^admin/', admin.site.urls),
]
File "site-packages/django/core/checks/urls.py", line 67, in check_pattern_startswith_slash
regex_pattern = pattern.regex.pattern
AttributeError: 'tuple' object has no attribute 'regex'
I suggest that we should create a new warning if the pattern is not a url() instance.
Change History (10)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:3 by , 10 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:4 by , 10 years ago
| Has patch: | set |
|---|---|
| Patch needs improvement: | set |
Left comments for improvement on the PR.
comment:6 by , 10 years ago
| Patch needs improvement: | unset |
|---|
comment:7 by , 10 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
comment:8 by , 10 years ago
| Patch needs improvement: | set |
|---|
Sorry for changing the patch after it had been reviewed. I've added a couple more patches to the pull request
- Added explicit test that URL checks are recursive, and simplified other url configs
- Added hints when users have a string or tuple instead of a url() instance
I think the text of the hints could be improved. I'm not 100% sure that the tuple hint is necessary - maybe saying the main warning 'Ensure that urlpatterns is a list' is enough.
comment:9 by , 10 years ago
| Patch needs improvement: | unset |
|---|
I thought this might be a good ticket if somebody's looking for a ticket during the Djangocon EU sprints. If it's not picked up, then I'll take a look at it next week.