Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[py3] Avoided passing a lazy string to urlparse.

This causes an exception under Python 3.

Fixed #18776.
  • Loading branch information...
commit de3ad8bb2d14ccf878121b96e6e0359dd8b1f9d5 1 parent a120fac
@aaugustin aaugustin authored
5 django/contrib/auth/
@@ -7,6 +7,7 @@
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.core.exceptions import PermissionDenied
from django.utils.decorators import available_attrs
+from django.utils.encoding import force_str
def user_passes_test(test_func, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME):
@@ -22,9 +23,11 @@ def _wrapped_view(request, *args, **kwargs):
if test_func(request.user):
return view_func(request, *args, **kwargs)
path = request.build_absolute_uri()
+ # urlparse chokes on lazy objects in Python 3
+ login_url_as_str = force_str(login_url or settings.LOGIN_URL)
# If the login url is the same scheme and net location then just
# use the path as the "next" url.
- login_scheme, login_netloc = urlparse(login_url or settings.LOGIN_URL)[:2]
+ login_scheme, login_netloc = urlparse(login_url_as_str)[:2]
current_scheme, current_netloc = urlparse(path)[:2]
if ((not login_scheme or login_scheme == current_scheme) and
(not login_netloc or login_netloc == current_netloc)):
7 django/contrib/auth/
@@ -7,6 +7,7 @@
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect, QueryDict
from django.template.response import TemplateResponse
+from django.utils.encoding import force_str
from django.utils.http import base36_to_int
from django.utils.translation import ugettext as _
from django.views.decorators.debug import sensitive_post_parameters
@@ -116,10 +117,10 @@ def redirect_to_login(next, login_url=None,
Redirects the user to the login page, passing the given 'next' page
- if not login_url:
- login_url = settings.LOGIN_URL
+ # urlparse chokes on lazy objects in Python 3
+ login_url_as_str = force_str(login_url or settings.LOGIN_URL)
- login_url_parts = list(urlparse(login_url))
+ login_url_parts = list(urlparse(login_url_as_str))
if redirect_field_name:
querystring = QueryDict(login_url_parts[4], mutable=True)
querystring[redirect_field_name] = next
Please sign in to comment.
Something went wrong with that request. Please try again.