[Django] #26440: Add check that all items in url patterns are url instances

13 views
Skip to first unread message

Django

unread,
Apr 1, 2016, 4:46:56 PM4/1/16
to django-...@googlegroups.com
#26440: Add check that all items in url patterns are url instances
--------------------------------------+--------------------
Reporter: alasdairnicol | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (System checks) | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+--------------------
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/26440>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 1, 2016, 4:50:52 PM4/1/16
to django-...@googlegroups.com
#26440: Add check that all items in url patterns are url instances
-------------------------------------+-------------------------------------
Reporter: alasdairnicol | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by alasdairnicol):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/26440#comment:1>

Django

unread,
Apr 1, 2016, 7:37:48 PM4/1/16
to django-...@googlegroups.com
#26440: Add check that all items in url patterns are url instances
--------------------------------------+------------------------------------

Reporter: alasdairnicol | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (System checks) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/26440#comment:2>

Django

unread,
Apr 2, 2016, 4:42:18 AM4/2/16
to django-...@googlegroups.com
#26440: Add check that all items in url patterns are url instances
--------------------------------------+------------------------------------
Reporter: alasdairnicol | Owner: burhan
Type: Cleanup/optimization | Status: assigned

Component: Core (System checks) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by burhan):

* owner: nobody => burhan
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/26440#comment:3>

Django

unread,
Apr 2, 2016, 9:24:28 AM4/2/16
to django-...@googlegroups.com
#26440: Add check that all items in url patterns are url instances
--------------------------------------+------------------------------------
Reporter: alasdairnicol | Owner: burhan
Type: Cleanup/optimization | Status: assigned
Component: Core (System checks) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1
* has_patch: 0 => 1


Comment:

Left comments for improvement on the
[https://github.com/django/django/pull/6375 PR].

--
Ticket URL: <https://code.djangoproject.com/ticket/26440#comment:4>

Django

unread,
Apr 26, 2016, 6:18:39 PM4/26/16
to django-...@googlegroups.com
#26440: Add check that all items in url patterns are url instances
--------------------------------------+------------------------------------
Reporter: alasdairnicol | Owner: burhan
Type: Cleanup/optimization | Status: assigned
Component: Core (System checks) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by alasdairnicol):

I've created a new pr, which builds on burhan's work.

https://github.com/django/django/pull/6514

--
Ticket URL: <https://code.djangoproject.com/ticket/26440#comment:5>

Django

unread,
Apr 26, 2016, 8:17:54 PM4/26/16
to django-...@googlegroups.com
#26440: Add check that all items in url patterns are url instances
--------------------------------------+------------------------------------
Reporter: alasdairnicol | Owner: burhan
Type: Cleanup/optimization | Status: assigned
Component: Core (System checks) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/26440#comment:6>

Django

unread,
Apr 27, 2016, 10:02:20 AM4/27/16
to django-...@googlegroups.com
#26440: Add check that all items in url patterns are url instances
-------------------------------------+-------------------------------------
Reporter: alasdairnicol | Owner: burhan
Type: | Status: assigned

Cleanup/optimization |
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/26440#comment:7>

Django

unread,
Apr 28, 2016, 5:07:18 PM4/28/16
to django-...@googlegroups.com
#26440: Add check that all items in url patterns are url instances
-------------------------------------+-------------------------------------
Reporter: alasdairnicol | Owner: burhan
Type: | Status: assigned
Cleanup/optimization |
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by alasdairnicol):

* needs_better_patch: 0 => 1


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/26440#comment:8>

Django

unread,
Apr 30, 2016, 5:16:54 PM4/30/16
to django-...@googlegroups.com
#26440: Add check that all items in url patterns are url instances
-------------------------------------+-------------------------------------
Reporter: alasdairnicol | Owner: burhan
Type: | Status: assigned
Cleanup/optimization |
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/26440#comment:9>

Django

unread,
Apr 30, 2016, 8:28:36 PM4/30/16
to django-...@googlegroups.com
#26440: Add check that all items in url patterns are url instances
-------------------------------------+-------------------------------------
Reporter: alasdairnicol | Owner: burhan
Type: | Status: closed

Cleanup/optimization |
Component: Core (System | Version: master
checks) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"eb5d7bc2f465b055f4eb54a3d238502bdddb6d7e" eb5d7bc2]:
{{{
#!CommitTicketReference repository=""
revision="eb5d7bc2f465b055f4eb54a3d238502bdddb6d7e"
Fixed #26440 -- Added a warning for non-url()s in urlpatterns.

Thanks Burhan Khalid for the initial patch and knbk/timgraham
for review.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26440#comment:10>

Reply all
Reply to author
Forward
0 new messages