Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #17076 -- When reversing a URL fails, inform the user which pat…

…terns were tried.
  • Loading branch information...
commit 8365ed08b83591bf6d7ddb3b3cb066d8325573bb 1 parent 0f3f88e
@Wilfred Wilfred authored mjtamlyn committed
Showing with 18 additions and 1 deletion.
  1. +4 −1 django/core/urlresolvers.py
  2. +14 −0 tests/urlpatterns_reverse/tests.py
View
5 django/core/urlresolvers.py
@@ -422,8 +422,11 @@ def _reverse_with_prefix(self, lookup_view, _prefix, *args, **kwargs):
lookup_view_s = "%s.%s" % (m, n)
else:
lookup_view_s = lookup_view
+
+ patterns = [pattern for (possibility, pattern, defaults) in possibilities]
raise NoReverseMatch("Reverse for '%s' with arguments '%s' and keyword "
- "arguments '%s' not found." % (lookup_view_s, args, kwargs))
+ "arguments '%s' not found. %d pattern(s) tried: %s" %
+ (lookup_view_s, args, kwargs, len(patterns), patterns))
class LocaleRegexURLResolver(RegexURLResolver):
"""
View
14 tests/urlpatterns_reverse/tests.py
@@ -192,6 +192,20 @@ def test_non_urlsafe_prefix_with_args(self):
self.assertEqual('/%7Eme/places/1/',
reverse('places', args=[1], prefix='/~me/'))
+ def test_patterns_reported(self):
+ # Regression for #17076
+ try:
+ # this url exists, but requires an argument
+ reverse("people", args=[])
+ except NoReverseMatch as e:
+ pattern_description = r"1 pattern(s) tried: ['people/(?P<name>\\w+)/$']"
+ self.assertIn(pattern_description, str(e))
+ else:
+ # we can't use .assertRaises, since we want to inspect the
+ # exception
+ self.fail("Expected a NoReverseMatch, but none occurred.")
+
+
class ResolverTests(unittest.TestCase):
def test_resolver_repr(self):
"""
Please sign in to comment.
Something went wrong with that request. Please try again.