[Django] #26039: Bug with Views being nested partials

17 views
Skip to first unread message

Django

unread,
Jan 5, 2016, 2:07:05 PM1/5/16
to django-...@googlegroups.com
#26039: Bug with Views being nested partials
-----------------------------+---------------------------------
Reporter: gst | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: master
Severity: Normal | Keywords: reverse partial url
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
-----------------------------+---------------------------------
If you define a view `v2` like this:

{{{
def view(request):
pass

v1 = functools.partial(view)
v2 = functools.partial(v1)
}}}

then set `v2` as the view for some url, then you'll get an attribute error
if you try reverse() on it :

AttributeError: 'functools.partial' object has no attribute '__module__'

{{{
File "/home/gstarck/work/public/python/django-
all/django/django/urls/base.py", line 91, in reverse
return force_text(iri_to_uri(resolver._reverse_with_prefix(view,
prefix, *args, **kwargs)))
File "/home/gstarck/work/public/python/django-
all/django/django/urls/resolvers.py", line 323, in _reverse_with_prefix
self._populate()
File "/home/gstarck/work/public/python/django-
all/django/django/urls/resolvers.py", line 183, in _populate
self._callback_strs.add(pattern.lookup_str)
File "/home/gstarck/work/public/python/django-
all/django/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/gstarck/work/public/python/django-
all/django/django/urls/resolvers.py", line 141, in lookup_str
return callback.__module__ + "." + callback.__class__.__name__
AttributeError: 'functools.partial' object has no attribute '__module__'
}}}

I have a patch / test case for this..

--
Ticket URL: <https://code.djangoproject.com/ticket/26039>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 5, 2016, 2:08:48 PM1/5/16
to django-...@googlegroups.com
#26039: Bug with Views being nested partials
-------------------------------------+-------------------------------------

Reporter: gst | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: master
Severity: Normal | Resolution:

Keywords: reverse partial url | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by gst):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

I've initially raised my concern here:
https://github.com/django/django/pull/5578#discussion_r48514488

--
Ticket URL: <https://code.djangoproject.com/ticket/26039#comment:1>

Django

unread,
Jan 5, 2016, 3:57:49 PM1/5/16
to django-...@googlegroups.com
#26039: Bug with Views being nested partials
-------------------------------------+------------------------------------

Reporter: gst | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: master
Severity: Normal | Resolution:
Keywords: reverse partial url | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by charettes):

* has_patch: 1 => 0
* stage: Unreviewed => Accepted


Comment:

Please check ''has patch'' when it is ready.

--
Ticket URL: <https://code.djangoproject.com/ticket/26039#comment:2>

Django

unread,
Jan 5, 2016, 4:53:36 PM1/5/16
to django-...@googlegroups.com
#26039: Bug with Views being nested partials
-------------------------------------+------------------------------------

Reporter: gst | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: master
Severity: Normal | Resolution:
Keywords: reverse partial url | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by gst):

* has_patch: 0 => 1


Comment:

I have a test case as well as a patch.. should I submit that as PR ?

--
Ticket URL: <https://code.djangoproject.com/ticket/26039#comment:3>

Django

unread,
Jan 5, 2016, 5:32:20 PM1/5/16
to django-...@googlegroups.com
#26039: Bug with Views being nested partials
-------------------------------------+------------------------------------

Reporter: gst | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: master
Severity: Normal | Resolution:
Keywords: reverse partial url | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+------------------------------------

Comment (by charettes):

Please do, make sure the PR also refers to this ticket: `Fixed #26039 --
Unwrapped nested partials in URL reversal.`

--
Ticket URL: <https://code.djangoproject.com/ticket/26039#comment:4>

Django

unread,
Jan 6, 2016, 12:05:43 PM1/6/16
to django-...@googlegroups.com
#26039: Bug with Views being nested partials
-------------------------------------+------------------------------------

Reporter: gst | Owner: nobody
Type: Bug | Status: new
Component: Core (URLs) | Version: master
Severity: Normal | Resolution:
Keywords: reverse partial url | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+------------------------------------

Comment (by timgraham):

[https://github.com/django/django/pull/5937 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/26039#comment:5>

Django

unread,
Jan 6, 2016, 3:26:03 PM1/6/16
to django-...@googlegroups.com
#26039: Bug with Views being nested partials
-------------------------------------+------------------------------------
Reporter: gst | Owner: nobody
Type: Bug | Status: closed

Component: Core (URLs) | Version: master
Severity: Normal | Resolution: fixed

Keywords: reverse partial url | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"9f9921e89c5c559ff4324f8cf968007cefbf6442" 9f9921e]:
{{{
#!CommitTicketReference repository=""
revision="9f9921e89c5c559ff4324f8cf968007cefbf6442"


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.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26039#comment:6>

Reply all
Reply to author
Forward
0 new messages