Opened 10 years ago

Closed 10 years ago

#3749 closed (fixed)

FilterNode does not supply full context

Reported by: Zak Johnson <zakj@…> Owned by: Adrian Holovaty
Component: Template system Version: master
Severity: Keywords: FilterNode filter tag
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

FilterNode truncates the context it passes to its filter, causing variable filter arguments to raise VariableDoesNotExist. For example, this works:

{{ obj|cut:request.GET.cut }}

This raises VariableDoesNotExist:

{% filter cut:request.GET.cut %}{{ obj }}{% endfilter %}

Attachments (2)

FilterNode.patch (600 bytes) - added by Zak Johnson <zakj@…> 10 years ago.
FilterNode.2.patch (1.3 KB) - added by Zak Johnson <zakj@…> 10 years ago.
patch with regression test

Download all attachments as: .zip

Change History (10)

Changed 10 years ago by Zak Johnson <zakj@…>

Attachment: FilterNode.patch added

comment:1 Changed 10 years ago by Simon G. <dev@…>

Triage Stage: UnreviewedReady for checkin

comment:2 Changed 10 years ago by Adrian Holovaty

Needs tests: set
Triage Stage: Ready for checkinAccepted

Thanks for the patch. Could you (or somebody) include some unit tests, so we can check this in?

Changed 10 years ago by Zak Johnson <zakj@…>

Attachment: FilterNode.2.patch added

patch with regression test

comment:3 Changed 10 years ago by Zak Johnson <zakj@…>

Needs tests: unset
Triage Stage: AcceptedReady for checkin

comment:4 Changed 10 years ago by Chris Beaven

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

Maybe I'm missing something, but context is being popped at the end of the render method even though it was never pushed. Won't this screw up the context after this node?

comment:5 Changed 10 years ago by Zak Johnson <zakj@…>

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

Context.update() pushes its argument to the beginning of the context. See http://code.djangoproject.com/browser/django/trunk/django/template/context.py#L61. All unit tests pass following this patch.

comment:6 Changed 10 years ago by Chris Beaven

My mistake, thanks for checking this - I didn't get around to doing it myself.

comment:7 Changed 10 years ago by Zak Johnson <zakj@…>

No worries; you've got a lot of tickets to get through. :)

comment:8 Changed 10 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(In [5052]) Fixed #3749 -- Set the context correctly when using the "filter" template tag.
Thanks, Zak Johnson.

Note: See TracTickets for help on using tickets.
Back to Top