[Django] #34812: Validate that URLConf modules contain a urlpatterns entry

9 views
Skip to first unread message

Django

unread,
Sep 3, 2023, 8:20:54 AM9/3/23
to django-...@googlegroups.com
#34812: Validate that URLConf modules contain a urlpatterns entry
---------------------------------------+------------------------
Reporter: The Epic | Owner: nobody
Type: New feature | Status: new
Component: Core (URLs) | Version: 4.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------+------------------------
Hey everyone. I've seen a few people on Discord mention that Django
reported circular imports due to their URL configs, and in at least one
case the problem was that the user made a typo in `urlpatterns`.

I think it would be grand if Django checked for the existence of the
`urlpatterns` attribute when passing a module to `include` and raised a
clearer Exception if it is absent.

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

Django

unread,
Sep 3, 2023, 8:41:31 AM9/3/23
to django-...@googlegroups.com
#34812: Validate that URLConf modules contain a urlpatterns entry
-----------------------------+--------------------------------------

Reporter: The Epic | Owner: nobody
Type: New feature | Status: new
Component: Core (URLs) | Version: 4.2
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------

Comment (by David Sanders):

Hello,

Django already does this with:

> django.core.exceptions.ImproperlyConfigured: The included URLconf
'<module 'foo.urls' from '/path/to/foo/urls.py'>' does not appear to have
any patterns in it. If you see the 'urlpatterns' variable with valid
patterns in the file then the issue is probably caused by a circular
import.

🤔

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

Django

unread,
Sep 3, 2023, 8:54:54 AM9/3/23
to django-...@googlegroups.com
#34812: Validate that URLConf modules contain a urlpatterns entry
-----------------------------+--------------------------------------
Reporter: The Epic | Owner: nobody
Type: New feature | Status: new
Component: Core (URLs) | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------

Comment (by The Epic):

Replying to [comment:1 David Sanders]:


> Hello,
>
> Django already does this with:
>
> > django.core.exceptions.ImproperlyConfigured: The included URLconf
'<module 'foo.urls' from '/path/to/foo/urls.py'>' does not appear to have
any patterns in it. If you see the 'urlpatterns' variable with valid
patterns in the file then the issue is probably caused by a circular
import.
>
> 🤔

Oh, you're right. I guess the message should be clearer. I don't really
see how circular imports would affect it.

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

Django

unread,
Sep 3, 2023, 10:26:38 AM9/3/23
to django-...@googlegroups.com
#34812: Validate that URLConf modules contain a urlpatterns entry
-----------------------------+--------------------------------------
Reporter: The Epic | Owner: nobody
Type: New feature | Status: closed

Component: Core (URLs) | Version: 4.2
Severity: Normal | Resolution: worksforme

Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by David Sanders):

* status: new => closed
* resolution: => worksforme


Comment:

Ok marking as worksforme… raise a discussion on the Django Forum if you'd
like to discuss changing the message 👍

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

Reply all
Reply to author
Forward
0 new messages