Skip to content

Commit

Permalink
Fixed #22486 -- Restored the ability to reverse views created using f…
Browse files Browse the repository at this point in the history
…unctools.partial.

Regression in 8b93b31.

Thanks rcoup for the report.
  • Loading branch information
Preston Timmons authored and timgraham committed Apr 23, 2014
1 parent c3152e5 commit 3c06b2f
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 1 deletion.
4 changes: 4 additions & 0 deletions django/core/urlresolvers.py
Expand Up @@ -8,6 +8,7 @@
"""
from __future__ import unicode_literals

import functools
from importlib import import_module
import re
from threading import local
Expand Down Expand Up @@ -270,6 +271,9 @@ def _populate(self):
self._callback_strs.add(pattern._callback_str)
elif hasattr(pattern, '_callback'):
callback = pattern._callback
if isinstance(callback, functools.partial):
callback = callback.func

if not hasattr(callback, '__name__'):
lookup_str = callback.__module__ + "." + callback.__class__.__name__
else:
Expand Down
14 changes: 14 additions & 0 deletions docs/releases/1.4.12.txt
@@ -0,0 +1,14 @@
===========================
Django 1.4.12 release notes
===========================

*Under development*

Django 1.4.12 fixes a regression in the 1.4.11 security release.

Bugfixes
========

* Restored the ability to :meth:`~django.core.urlresolvers.reverse` views
created using :func:`functools.partial()`
(`#22486 <http://code.djangoproject.com/ticket/22486>`_)
14 changes: 14 additions & 0 deletions docs/releases/1.5.7.txt
@@ -0,0 +1,14 @@
==========================
Django 1.5.7 release notes
==========================

*Under development*

Django 1.5.7 fixes a regression in the 1.5.6 security release.

Bugfixes
========

* Restored the ability to :meth:`~django.core.urlresolvers.reverse` views
created using :func:`functools.partial()`
(`#22486 <http://code.djangoproject.com/ticket/22486>`_)
4 changes: 4 additions & 0 deletions docs/releases/1.6.4.txt
Expand Up @@ -12,3 +12,7 @@ Bugfixes
* Added backwards compatibility support for the :mod:`django.contrib.messages`
cookie format of Django 1.4 and earlier to facilitate upgrading to 1.6 from
1.4 (`#22426 <http://code.djangoproject.com/ticket/22426>`_).

* Restored the ability to :meth:`~django.core.urlresolvers.reverse` views
created using :func:`functools.partial()`
(`#22486 <http://code.djangoproject.com/ticket/22486>`_)
2 changes: 2 additions & 0 deletions docs/releases/index.txt
Expand Up @@ -47,6 +47,7 @@ Final releases
.. toctree::
:maxdepth: 1

1.5.7
1.5.6
1.5.5
1.5.4
Expand All @@ -60,6 +61,7 @@ Final releases
.. toctree::
:maxdepth: 1

1.4.12
1.4.11
1.4.10
1.4.9
Expand Down
6 changes: 5 additions & 1 deletion tests/urlpatterns_reverse/urls.py
Expand Up @@ -2,7 +2,7 @@

from django.conf.urls import patterns, url, include

from .views import empty_view, absolute_kwargs_view
from .views import empty_view, empty_view_partial, empty_view_wrapped, absolute_kwargs_view


other_patterns = [
Expand Down Expand Up @@ -54,6 +54,10 @@
url(r'^outer-no-kwargs/([0-9]+)/', include('urlpatterns_reverse.included_no_kwargs_urls')),
url('', include('urlpatterns_reverse.extra_urls')),

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

# This is non-reversible, but we shouldn't blow up when parsing it.
url(r'^(?:foo|bar)(\w+)/$', empty_view, name="disjunction"),

Expand Down
10 changes: 10 additions & 0 deletions tests/urlpatterns_reverse/views.py
@@ -1,3 +1,5 @@
from functools import partial, update_wrapper

from django.http import HttpResponse
from django.views.generic import RedirectView
from django.core.urlresolvers import reverse_lazy
Expand Down Expand Up @@ -55,3 +57,11 @@ def login_required_view(request):

def bad_view(request, *args, **kwargs):
raise ValueError("I don't think I'm getting good value for this view")


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


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

0 comments on commit 3c06b2f

Please sign in to comment.