Opened 22 months ago

Closed 19 months ago

Last modified 19 months 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 22 months ago by mitar

  • Cc mmitar@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 21 months ago by timo

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 21 months ago by mitar

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

comment:4 Changed 19 months ago by aaugustin

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

comment:5 Changed 19 months ago by timo

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

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 19 months 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