#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:
> 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!
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'
}}}
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#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/063.085a1c0648d7a4eb098aa616aad2e6af%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.