Opened 6 years ago

Closed 5 years ago

Last modified 5 years ago

#21694 closed Bug (wontfix)

Default filter cannot be used with undefined variables

Reported by: Mitar Owned by: nobody
Component: Template system Version: 1.4
Severity: Normal Keywords:
Cc: mmitar@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I wanted to assign a default value from a variable:

{% with heading=heading|default:title|default:"unknown" %}

{% endwith %}

But if variable title is missing, rendering simply fails, without any exception (even in debug mode) but also without setting heading to "unknown". From looking at the source code I understand that this happens because default filter is implemented using simple tags which expect that all filter arguments are defined, but it is unexpected behavior in this particular case.

Change History (6)

comment:1 Changed 6 years ago by Mitar

Cc: mmitar@… added

comment:2 Changed 6 years ago by Tim Graham

As you described, I'm not sure it's feasible given the current implementation. Can you propose a patch to fix it?

comment:3 Changed 6 years ago by Mitar

Default filter should be probably moved into a special case inside the FilterExpression handling.

comment:4 Changed 5 years ago by Aymeric Augustin

That doesn't sound like a very good design :(

comment:5 Changed 5 years ago by Tim Graham

Resolution: wontfix
Status: newclosed

I think it will probably be better not to support this. For one, it will force people not to put so much logic in their templates.

comment:6 Changed 5 years ago by Mitar

The issue is that there is no error or warning when user does this. Even in debug mode. There should be at least an exception when this happens. Otherwise it is really hard to capture that this is happening.

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