{{{
@register.filter
@mark_safe
def myfilter(value):
...
}}}
Smilarly for tags. This has worked in Django 1.11, however, with Django
2.0, this leads to the TemplateError saying that "myfilter requires 0
arguments, 1 provided". For tags, it results in an IndexError because the
"params" list when processing the tag is empty.
If I make @mark_safe the outmost (i.e. first) decorator, no exception
occurs – but the output is escaped HTML instead of passed-through HTML.
--
Ticket URL: <https://code.djangoproject.com/ticket/29400>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "django.tb" added.
Taceback when using @mark_safe with a template filter function.
* component: Uncategorized => Template system
* type: Uncategorized => Bug
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted
Comment:
Bisected to 620e9dd31a2146d70de740f96a8cb9a6db054fc7.
--
Ticket URL: <https://code.djangoproject.com/ticket/29400#comment:1>
* status: new => assigned
* owner: nobody => oliver
--
Ticket URL: <https://code.djangoproject.com/ticket/29400#comment:2>
Comment (by Ryan Rubin):
Replying to [comment:2 oliver]:
I'm happy to work on this if you need to relinquish it.
--
Ticket URL: <https://code.djangoproject.com/ticket/29400#comment:3>
Comment (by Ryan Rubin):
I went ahead and took a look, since it was 10 days past claimed. I was
unable to reproduce for any tags, but I did for filters. As of the
bisected commit, `inspect.getfullargspec` is being passed the function,
but if that function is decorated, `inspect.getfullargspec` does not read
`__wrapped__` attributes as of Python 3.4:
https://docs.python.org/3/library/inspect.html#inspect.getfullargspec
The function is checked for a _decorated_function attribute, but that's
not always present. `inspect.unwrap` will get the original function for
the call to `inspect.getfullargspec`, though. I've opened a PR here:
https://github.com/django/django/pull/9979
--
Ticket URL: <https://code.djangoproject.com/ticket/29400#comment:4>
* has_patch: 0 => 1
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/29400#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"a8d12bc28069d56e0306770ab9c73738293663f7" a8d12bc2]:
{{{
#!CommitTicketReference repository=""
revision="a8d12bc28069d56e0306770ab9c73738293663f7"
Fixed #29400 -- Fixed crash in custom template filters that use decorated
functions.
Regression in 620e9dd31a2146d70de740f96a8cb9a6db054fc7.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29400#comment:6>
Comment (by Tim Graham <timograham@…>):
In [changeset:"6b91152a103f7c5cbefcf44741e6b03611724714" 6b91152]:
{{{
#!CommitTicketReference repository=""
revision="6b91152a103f7c5cbefcf44741e6b03611724714"
[2.1.x] Fixed #29400 -- Fixed crash in custom template filters that use
decorated functions.
Regression in 620e9dd31a2146d70de740f96a8cb9a6db054fc7.
Backport of a8d12bc28069d56e0306770ab9c73738293663f7 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29400#comment:7>
Comment (by Tim Graham <timograham@…>):
In [changeset:"c2a1af883e18b93a77080650feb9e959536d51ca" c2a1af88]:
{{{
#!CommitTicketReference repository=""
revision="c2a1af883e18b93a77080650feb9e959536d51ca"
[2.0.x] Fixed #29400 -- Fixed crash in custom template filters that use
decorated functions.
Regression in 620e9dd31a2146d70de740f96a8cb9a6db054fc7.
Backport of a8d12bc28069d56e0306770ab9c73738293663f7 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29400#comment:8>