Skip to content
Permalink
Browse files

Override urlconf_module so that Django system checks don't crash. (#…

…6719)

* Add a test case for #6717.

* Override urlconf_module so that Django system checks don't crash.

Without this fix, Django system checks in Django 2.2 will try to resolve the
"app_resolver" module, which does not exist. Overriding ``urlconf_module``
prevents the issue.

Fixes #6717
  • Loading branch information...
lddubeau authored and FinalAngel committed Aug 27, 2019
1 parent 31d1295 commit efbeaa0be5f9cac12d51ffdbca7716a01a68740a
Showing with 26 additions and 6 deletions.
  1. +14 −6 cms/appresolver.py
  2. +12 −0 cms/tests/test_apphooks.py
@@ -59,20 +59,28 @@ def applications_page_check(request, current_page=None, path=None):
pass
return None


class AppRegexURLResolver(URLResolver):

def __init__(self, *args, **kwargs):
self.page_id = None
self.url_patterns_dict = {}
super(AppRegexURLResolver, self).__init__(*args, **kwargs)

@property
def urlconf_module(self):
# It is valid for urlconf_module to be a list of patterns. So we just
# return the list here.
#
# See https://github.com/django/django/blob/2.2.4/django/urls/resolvers.py#L578
#
return self.url_patterns_dict.get(get_language(), [])

# On URLResolver the url_patterns property is cached and thus calls made after
# language changes (different return values for get_language()) would not return the
# right value. Overriding here prevents caching.
@property
def url_patterns(self):
language = get_language()
if language in self.url_patterns_dict:
return self.url_patterns_dict[language]
else:
return []
return self.urlconf_module

def resolve_page_id(self, path):
"""Resolves requested path similar way how resolve does, but instead
@@ -7,6 +7,7 @@
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site
from django.core import checks
from django.core.cache import cache
from django.test.utils import override_settings
from django.urls import NoReverseMatch, clear_url_caches, resolve, reverse
@@ -173,6 +174,17 @@ def test_apphook_on_homepage(self):

self.apphook_clear()

@override_settings(ROOT_URLCONF='cms.test_utils.project.urls_for_apphook_tests')
def test_apphook_does_not_crash_django_checks(self):
# This test case reproduced the situation causing the error reported in issue #6717.
self.apphook_clear()
superuser = get_user_model().objects.create_superuser('admin', 'admin@admin.com', 'admin')
create_page("apphooked-page", "nav_playground.html", "en",
created_by=superuser, published=True, apphook="SampleApp")
self.reload_urls()
checks.run_checks()
self.apphook_clear()

@override_settings(ROOT_URLCONF='cms.test_utils.project.urls_for_apphook_tests')
def test_apphook_on_root_reverse(self):
self.apphook_clear()

0 comments on commit efbeaa0

Please sign in to comment.
You can’t perform that action at this time.