From c1ef234e310fb984ced37eac8c8b90f5b6155e5f Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Thu, 18 Sep 2014 13:03:09 -0700 Subject: [PATCH] Fixed #23522 -- Changed reverse() to return a Unicode string; not bytes --- django/core/urlresolvers.py | 4 ++-- docs/releases/1.8.txt | 4 ++++ tests/urlpatterns_reverse/tests.py | 7 +++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py index eff7e078e4..62e3949df8 100644 --- a/django/core/urlresolvers.py +++ b/django/core/urlresolvers.py @@ -577,9 +577,9 @@ def reverse(viewname, urlconf=None, args=None, kwargs=None, prefix=None, current if ns_pattern: resolver = get_ns_resolver(ns_pattern, resolver) - return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)) + return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))) -reverse_lazy = lazy(reverse, str) +reverse_lazy = lazy(reverse, six.text_type) def clear_url_caches(): diff --git a/docs/releases/1.8.txt b/docs/releases/1.8.txt index 01e48b75e4..892dbd47b2 100644 --- a/docs/releases/1.8.txt +++ b/docs/releases/1.8.txt @@ -607,6 +607,10 @@ Miscellaneous * The default max size of the Oracle test tablespace has increased from 200M to 500M. +* :func:`~django.core.urlresolvers.reverse` and + :func:`~django.core.urlresolvers.reverse_lazy` now return Unicode strings + instead of byte strings. + .. _deprecated-features-1.8: Features deprecated in 1.8 diff --git a/tests/urlpatterns_reverse/tests.py b/tests/urlpatterns_reverse/tests.py index dbb1836b7a..9e5e4f513f 100644 --- a/tests/urlpatterns_reverse/tests.py +++ b/tests/urlpatterns_reverse/tests.py @@ -222,6 +222,13 @@ class URLPatternReverse(TestCase): # exception self.fail("Expected a NoReverseMatch, but none occurred.") + def test_reverse_returns_unicode(self): + name, expected, args, kwargs = test_data[0] + self.assertIsInstance( + reverse(name, args=args, kwargs=kwargs), + six.text_type + ) + class ResolverTests(unittest.TestCase): def test_resolver_repr(self):