Commit 9f9921e8 authored by Grégory Starck's avatar Grégory Starck Committed by Tim Graham
Browse files

Fixed #26039 -- Unwrapped nested partials in URL reversal.

Prior to Python 3.5 nested partials need to be fully "unfolded"
to get the actual function.
parent 632a9f21
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -135,7 +135,9 @@ class RegexURLPattern(LocaleRegexProvider):
        'path.to.ClassBasedView').
        """
        callback = self.callback
        if isinstance(callback, functools.partial):
        # Python 3.5 collapses nested partials, so can change "while" to "if"
        # when it's the minimum supported version.
        while isinstance(callback, functools.partial):
            callback = callback.func
        if not hasattr(callback, '__name__'):
            return callback.__module__ + "." + callback.__class__.__name__
+3 −2
Original line number Diff line number Diff line
from django.conf.urls import include, url

from .views import (
    absolute_kwargs_view, defaults_view, empty_view, empty_view_partial,
    empty_view_wrapped, nested_view,
    absolute_kwargs_view, defaults_view, empty_view, empty_view_nested_partial,
    empty_view_partial, empty_view_wrapped, nested_view,
)

other_patterns = [
@@ -62,6 +62,7 @@ urlpatterns = [

    # Partials should be fine.
    url(r'^partial/', empty_view_partial, name="partial"),
    url(r'^partial_nested/', empty_view_nested_partial, name="partial_nested"),
    url(r'^partial_wrapped/', empty_view_wrapped, name="partial_wrapped"),

    # This is non-reversible, but we shouldn't blow up when parsing it.
+1 −2
Original line number Diff line number Diff line
@@ -55,8 +55,7 @@ def bad_view(request, *args, **kwargs):


empty_view_partial = partial(empty_view, template_name="template.html")


empty_view_nested_partial = partial(empty_view_partial, template_name="nested_partial.html")
empty_view_wrapped = update_wrapper(
    partial(empty_view, template_name="template.html"), empty_view,
)