[Django] #29400: mark_safe does not work as a decorator for filters and tags (regression)

63 views
Skip to first unread message

Django

unread,
May 12, 2018, 4:53:09 AM5/12/18
to django-...@googlegroups.com
#29400: mark_safe does not work as a decorator for filters and tags (regression)
-------------------------------------------+------------------------
Reporter: Torsten Bronger | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 2.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
With Django 1.11, I had the following pattern frequently in my code:

{{{
@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.

Django

unread,
May 12, 2018, 4:53:59 AM5/12/18
to django-...@googlegroups.com
#29400: mark_safe does not work as a decorator for filters and tags (regression)
---------------------------------+--------------------------------------

Reporter: Torsten Bronger | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 2.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Torsten Bronger):

* Attachment "django.tb" added.

Taceback when using @mark_safe with a template filter function.

Django

unread,
May 12, 2018, 2:36:17 PM5/12/18
to django-...@googlegroups.com
#29400: mark_safe() doesn't work as a decorator for template filters and tags
---------------------------------+------------------------------------

Reporter: Torsten Bronger | Owner: nobody
Type: Bug | Status: new
Component: Template system | Version: 2.0
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by Tim Graham):

* 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>

Django

unread,
May 15, 2018, 12:41:39 AM5/15/18
to django-...@googlegroups.com
#29400: mark_safe() doesn't work as a decorator for template filters and tags
---------------------------------+------------------------------------
Reporter: Torsten Bronger | Owner: oliver
Type: Bug | Status: assigned

Component: Template system | Version: 2.0
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by oliver):

* status: new => assigned
* owner: nobody => oliver


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

Django

unread,
May 24, 2018, 10:09:01 AM5/24/18
to django-...@googlegroups.com
#29400: mark_safe() doesn't work as a decorator for template filters and tags
---------------------------------+------------------------------------
Reporter: Torsten Bronger | Owner: oliver
Type: Bug | Status: assigned
Component: Template system | Version: 2.0
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

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>

Django

unread,
May 24, 2018, 6:59:54 PM5/24/18
to django-...@googlegroups.com
#29400: mark_safe() doesn't work as a decorator for template filters and tags
---------------------------------+------------------------------------
Reporter: Torsten Bronger | Owner: oliver
Type: Bug | Status: assigned
Component: Template system | Version: 2.0
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

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>

Django

unread,
May 25, 2018, 10:51:40 AM5/25/18
to django-...@googlegroups.com
#29400: mark_safe() doesn't work as a decorator for template filters and tags
-------------------------------------+-------------------------------------

Reporter: Torsten Bronger | Owner: oliver
Type: Bug | Status: assigned
Component: Template system | Version: 2.0
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1
* stage: Accepted => Ready for checkin


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

Django

unread,
May 25, 2018, 11:12:15 AM5/25/18
to django-...@googlegroups.com
#29400: mark_safe() doesn't work as a decorator for template filters and tags
-------------------------------------+-------------------------------------
Reporter: Torsten Bronger | Owner: oliver
Type: Bug | Status: closed

Component: Template system | Version: 2.0
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
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: 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>

Django

unread,
May 25, 2018, 11:20:32 AM5/25/18
to django-...@googlegroups.com
#29400: mark_safe() doesn't work as a decorator for template filters and tags
-------------------------------------+-------------------------------------
Reporter: Torsten Bronger | Owner: oliver
Type: Bug | Status: closed
Component: Template system | Version: 2.0
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
May 25, 2018, 11:22:30 AM5/25/18
to django-...@googlegroups.com
#29400: mark_safe() doesn't work as a decorator for template filters and tags
-------------------------------------+-------------------------------------
Reporter: Torsten Bronger | Owner: oliver
Type: Bug | Status: closed
Component: Template system | Version: 2.0
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages