Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #17892 -- Do not include whole RegexURLPattern lists in RegexUR…

…LResolver repr

Thanks milosu for the report and the initial patch.
  • Loading branch information...
commit 28fd876bae15df747d164dcae229840d2cf135ca 1 parent c6088bc
@claudep claudep authored
View
7 django/core/urlresolvers.py
@@ -245,8 +245,13 @@ def __init__(self, regex, urlconf_name, default_kwargs=None, app_name=None, name
self._app_dict = {}
def __repr__(self):
+ if isinstance(self.urlconf_name, list) and len(self.urlconf_name):
+ # Don't bother to output the whole list, it can be huge
+ urlconf_repr = '<%s list>' % self.urlconf_name[0].__class__.__name__
+ else:
+ urlconf_repr = repr(self.urlconf_name)
return force_str('<%s %s (%s:%s) %s>' % (
- self.__class__.__name__, self.urlconf_name, self.app_name,
+ self.__class__.__name__, urlconf_repr, self.app_name,
self.namespace, self.regex.pattern))
def _populate(self):
View
12 tests/regressiontests/urlpatterns_reverse/tests.py
@@ -6,7 +6,7 @@
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
from django.core.urlresolvers import (reverse, resolve, get_callable,
- NoReverseMatch, Resolver404, ResolverMatch, RegexURLResolver,
+ get_resolver, NoReverseMatch, Resolver404, ResolverMatch, RegexURLResolver,
RegexURLPattern)
from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect
from django.shortcuts import redirect
@@ -172,6 +172,16 @@ def test_reverse_none(self):
self.assertRaises(NoReverseMatch, reverse, None)
class ResolverTests(unittest.TestCase):
+ def test_resolver_repr(self):
+ """
+ Test repr of RegexURLResolver, especially when urlconf_name is a list
+ (#17892).
+ """
+ # Pick a resolver from a namespaced urlconf
+ resolver = get_resolver('regressiontests.urlpatterns_reverse.namespace_urls')
+ sub_resolver = resolver.namespace_dict['test-ns1'][1]
+ self.assertIn('<RegexURLPattern list>', repr(sub_resolver))
+
def test_non_regex(self):
"""
Verifies that we raise a Resolver404 if what we are resolving doesn't
Please sign in to comment.
Something went wrong with that request. Please try again.