[Django] #29102: ImproperlyConfigured URLConf on certain requests (unknown cause)

4 views
Skip to first unread message

Django

unread,
Feb 1, 2018, 11:12:52 PM2/1/18
to django-...@googlegroups.com
#29102: ImproperlyConfigured URLConf on certain requests (unknown cause)
-------------------------------------+-------------------------------------
Reporter: scone | Owner: nobody
Type: Bug | Status: new
Component: Core | Version: 2.0
(URLs) | Keywords: URLResolver,
Severity: Normal | urlconf
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I haven't been able to recreate the bug, but I receive the error in my
django.error log several times a day. The requests are usually for my
index "/" page or my details page "'<int:pk>/details" (url patterns given
below).

When I revisit the URL in the log that caused the error, it works fine.
The error shows that "patterns" is a module in these cases and it doesn't
have "urlpatterns" as an attribute.


I'm using Python 3.5.2 with Django 2.0. The codebase was original written
with Django 1.6 I believe. I recently migrated to 2.0 and that is when I
noticed the issue.

I modified django/urls/resolvers.py to log the 'patterns' variable and
most of the time I receive this list:


{{{
[<URLResolver <URLPattern list> (admin:admin) 'admin/'>,
<URLPattern '<int:pk>/details' [name='details']>,
<URLPattern 'check/' [name='check']>,
<URLPattern 'logout/' [name='logout']>,
<URLPattern 'search/' [name='search']>,
<URLPattern 'features/' [name='features']>,
<URLPattern 'terms-of-service/' [name='terms']>,
<URLPattern 'privacy-policy/' [name='privacy']>,
<URLPattern '' [name='index']>]
}}}


Here is my urls file:
app_name/urls.py


{{{
from django.urls import path, re_path
from django.contrib import admin

from app_name import views
from app_name.result_view import SubmissionDetailView

handler404 = 'app_name.views.not_found_view'

urlpatterns = [
path('admin/', admin.site.urls),
path('<int:pk>/details', SubmissionDetailView.as_view(),
name='details'),
path('check/', views.check, name='check'),
path('logout/', views.logout_view, name='logout'),
path('search/', views.search, name='search'),
path('features/', views.features, name='features'),
path('terms-of-service/', views.terms, name='terms'),
path('privacy-policy/', views.privacy, name='privacy'),
path('', views.index, name='index'),
]
}}}

Exception


{{{
django.core.exceptions.ImproperlyConfigured: The included URLconf
'app_name.urls' does not appear to have any patterns in it.
If you see valid patterns in the file then the issue is probably caused by
a circular import.
Traceback

/opt/web/env/lib/python3.5/site-packages/django/urls/resolvers.py in
url_patterns
iter(patterns)
Local Vars

Variable Value
msg ("The included URLconf '{name}' does not appear to have any
patterns in it. If "
'you see valid patterns in the file then the issue is probably caused by
a '
'circular import.')
patterns <module 'app_name.urls' from
'/opt/web/app/my_site/app_name/urls.py'>
self <URLResolver 'app_name.urls' (None:None) '^/'>

During handling of the above exception ('module' object is not iterable),
another exception occurred:

/opt/web/env/lib/python3.5/site-packages/django/core/handlers/exception.py
in inner
response = get_response(request)
[SNIP]

/opt/web/env/lib/python3.5/site-packages/django/urls/base.py in resolve
return get_resolver(urlconf).resolve(path)
Local Vars

Variable Value
path '/4567/details'
urlconf 'app_name.urls'

/opt/web/env/lib/python3.5/site-packages/django/urls/resolvers.py in
resolve
for pattern in self.url_patterns:
Local Vars

Variable Value
args ()
kwargs {}
match ('4567/details', (), {})
new_path '4567/details'
path '/4567/details'
self <URLResolver 'app_name.urls' (None:None) '^/'>
tried []

/opt/web/env/lib/python3.5/site-packages/django/utils/functional.py in
__get__
res = instance.__dict__[self.name] = self.func(instance)
Local Vars

Variable Value
cls <class 'django.urls.resolvers.URLResolver'>
instance <URLResolver 'app_name.urls' (None:None) '^/'>
self <django.utils.functional.cached_property object at
0x7f06c7d2c550>

/opt/web/env/lib/python3.5/site-packages/django/urls/resolvers.py in
url_patterns
raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
Local Vars

Variable Value
msg ("The included URLconf '{name}' does not appear to have any
patterns in it. If "
'you see valid patterns in the file then the issue is probably caused by
a '
'circular import.')
patterns <module 'app_name.urls' from
'/opt/web/app/my_site/app_name/urls.py'>
self <URLResolver 'app_name.urls' (None:None) '^/'>
}}}

I changed my reverse() calls to reverse_lazy(), just in case it's caused
by a reverse call happening before urls_patterns are loaded. I don't know
of any cases where this would happen in my app though.

99% of the time, this isn't an issue, but it does occur daily and I would
like to patch things up!

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

Django

unread,
Feb 1, 2018, 11:16:18 PM2/1/18
to django-...@googlegroups.com
#29102: ImproperlyConfigured URLConf on certain requests (unknown cause)
-------------------------------------+-------------------------------------
Reporter: scone | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: 2.0
Severity: Normal | Resolution:
Keywords: URLResolver, | Triage Stage:
urlconf | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by scone:

Old description:

>
> Exception
>

> packages/django/core/handlers/exception.py in inner

New description:

I haven't been able to recreate the bug, but I receive the error in my
django.error log several times a day. The requests are usually for my
index "/" page or my details page "'<int:pk>/details" (url patterns given
below).

When I revisit the URL in the log that caused the error, it works fine.
The error shows that "patterns" is a module in these cases and it doesn't
have "urlpatterns" as an attribute.


I'm using Python 3.5.2 with Django 2.0. The codebase was original written
with Django 1.6 I believe. I recently migrated to 2.0 and that is when I
noticed the issue.

I modified django/urls/resolvers.py to log the 'patterns' variable and
most of the time I receive this list:


{{{
[<URLResolver <URLPattern list> (admin:admin) 'admin/'>,
<URLPattern '<int:pk>/details' [name='details']>,
<URLPattern 'check/' [name='check']>,
<URLPattern 'logout/' [name='logout']>,
<URLPattern 'search/' [name='search']>,
<URLPattern 'features/' [name='features']>,
<URLPattern 'terms-of-service/' [name='terms']>,
<URLPattern 'privacy-policy/' [name='privacy']>,
<URLPattern '' [name='index']>]
}}}

I've set my app/urls.py file as the default ROOT_CONF:


{{{
ROOT_URLCONF = 'app_name.urls'
}}}

handler404 = 'app_name.views.not_found_view'

Exception

--

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

Django

unread,
Feb 2, 2018, 7:53:11 AM2/2/18
to django-...@googlegroups.com
#29102: ImproperlyConfigured URLConf on certain requests (unknown cause)
-------------------------------------+-------------------------------------
Reporter: scone | Owner: nobody
Type: Bug | Status: closed

Component: Core (URLs) | Version: 2.0
Severity: Normal | Resolution: needsinfo

Keywords: URLResolver, | Triage Stage:
urlconf | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

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


Comment:

I don't see anything unusual in your code or something that would suggest
a bug in Django. Please reopen if you confirm that Django is at fault.
Next time, please use [wiki:TicketClosingReasons/UseSupportChannels our
support channels] for "is it a bug?" questions.

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

Reply all
Reply to author
Forward
0 new messages