Opened 9 years ago
Closed 9 years ago
#26039 closed Bug (fixed)
Bug with Views being nested partials
Reported by: | Grégory Starck | Owned by: | nobody |
---|---|---|---|
Component: | Core (URLs) | Version: | dev |
Severity: | Normal | Keywords: | reverse partial url |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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..
Change History (6)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
Has patch: | unset |
---|---|
Triage Stage: | Unreviewed → Accepted |
Please check has patch when it is ready.
comment:3 by , 9 years ago
Has patch: | set |
---|
I have a test case as well as a patch.. should I submit that as PR ?
comment:4 by , 9 years ago
Please do, make sure the PR also refers to this ticket: Fixed #26039 -- Unwrapped nested partials in URL reversal.
Note:
See TracTickets
for help on using tickets.
I've initially raised my concern here: https://github.com/django/django/pull/5578#discussion_r48514488