Opened 11 years ago

Closed 11 years ago

Last modified 11 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

Description

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 by Mitar, 11 years ago

Cc: mmitar@… added

comment:2 by Tim Graham, 11 years ago

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

comment:3 by Mitar, 11 years ago

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

comment:4 by Aymeric Augustin, 11 years ago

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

comment:5 by Tim Graham, 11 years ago

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 by Mitar, 11 years ago

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