Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #21043 -- Made resolve() handle reverse_lazy objects.

Thanks Keryn Knight for the report.
  • Loading branch information...
commit df462cf7604578c2afd43b988b7ea1fe5e727896 1 parent c7c19ac
Dan Johnson danrjohnson authored timgraham committed
Showing with 15 additions and 1 deletion.
  1. +1 −0  django/core/urlresolvers.py
  2. +14 −1 tests/urlpatterns_reverse/tests.py
1  django/core/urlresolvers.py
View
@@ -311,6 +311,7 @@ def app_dict(self):
return self._app_dict[language_code]
def resolve(self, path):
+ path = force_text(path) # path may be a reverse_lazy object
tried = []
match = self.regex.search(path)
if match:
15 tests/urlpatterns_reverse/tests.py
View
@@ -8,7 +8,7 @@
from django.conf import settings
from django.contrib.auth.models import User
from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
-from django.core.urlresolvers import (reverse, resolve, get_callable,
+from django.core.urlresolvers import (reverse, reverse_lazy, resolve, get_callable,
get_resolver, NoReverseMatch, Resolver404, ResolverMatch, RegexURLResolver,
RegexURLPattern)
from django.http import HttpRequest, HttpResponseRedirect, HttpResponsePermanentRedirect
@@ -219,6 +219,19 @@ def test_resolver_repr(self):
sub_resolver = resolver.namespace_dict['test-ns1'][1]
self.assertIn('<RegexURLPattern list>', repr(sub_resolver))
+ def test_reverse_lazy_object_coercion_by_resolve(self):
+ """
+ Verifies lazy object returned by reverse_lazy is coerced to
+ text by resolve(). Previous to #21043, this would raise a TypeError.
+ """
+ urls = 'urlpatterns_reverse.named_urls'
+ proxy_url = reverse_lazy('named-url1', urlconf=urls)
+ resolver = get_resolver(urls)
+ try:
+ match = resolver.resolve(proxy_url)
+ except TypeError:
+ self.fail('Failed to coerce lazy object to text')
+
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.