From 28fd876bae15df747d164dcae229840d2cf135ca Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 1 Sep 2012 22:07:18 +0200 Subject: [PATCH] Fixed #17892 -- Do not include whole RegexURLPattern lists in RegexURLResolver repr Thanks milosu for the report and the initial patch. --- django/core/urlresolvers.py | 7 ++++++- tests/regressiontests/urlpatterns_reverse/tests.py | 12 +++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py index fe3bb49bbe5..af3df83d0a8 100644 --- a/django/core/urlresolvers.py +++ b/django/core/urlresolvers.py @@ -245,8 +245,13 @@ class RegexURLResolver(LocaleRegexProvider): 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): diff --git a/tests/regressiontests/urlpatterns_reverse/tests.py b/tests/regressiontests/urlpatterns_reverse/tests.py index b9c64183e5b..168892719ac 100644 --- a/tests/regressiontests/urlpatterns_reverse/tests.py +++ b/tests/regressiontests/urlpatterns_reverse/tests.py @@ -6,7 +6,7 @@ from __future__ import absolute_import, unicode_literals 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 @@ class URLPatternReverse(TestCase): 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('', repr(sub_resolver)) + def test_non_regex(self): """ Verifies that we raise a Resolver404 if what we are resolving doesn't