Code

Opened 7 years ago

Closed 7 years ago

#3749 closed (fixed)

FilterNode does not supply full context

Reported by: Zak Johnson <zakj@…> Owned by: adrian
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@…> 7 years ago.
FilterNode.2.patch (1.3 KB) - added by Zak Johnson <zakj@…> 7 years ago.
patch with regression test

Download all attachments as: .zip

Change History (10)

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

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

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Ready for checkin

comment:2 Changed 7 years ago by adrian

  • Needs tests set
  • Triage Stage changed from Ready for checkin to Accepted

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

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

patch with regression test

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

  • Needs tests unset
  • Triage Stage changed from Accepted to Ready for checkin

comment:4 Changed 7 years ago by SmileyChris

  • Patch needs improvement set
  • Triage Stage changed from Ready for checkin to Accepted

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 7 years ago by Zak Johnson <zakj@…>

  • Patch needs improvement unset
  • Triage Stage changed from Accepted to Ready 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 7 years ago by SmileyChris

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

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

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

comment:8 Changed 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.