Opened 7 years ago
Closed 7 years ago
#29102 closed Bug (needsinfo)
ImproperlyConfigured URLConf on certain requests (unknown cause)
Reported by: | scone | Owned by: | nobody |
---|---|---|---|
Component: | Core (URLs) | Version: | 2.0 |
Severity: | Normal | Keywords: | URLResolver, urlconf |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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!
Change History (2)
comment:1 by , 7 years ago
Description: | modified (diff) |
---|
comment:2 by , 7 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
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 our support channels for "is it a bug?" questions.