#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 , 11 years ago
Cc: | added |
---|
comment:2 by , 11 years ago
comment:3 by , 11 years ago
Default filter should be probably moved into a special case inside the FilterExpression
handling.
comment:5 by , 11 years ago
Resolution: | → wontfix |
---|---|
Status: | new → 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 by , 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.
As you described, I'm not sure it's feasible given the current implementation. Can you propose a patch to fix it?