Opened 9 years ago
Closed 9 years ago
#27726 closed Bug (invalid)
Template default_if_none filter is inconsistent between printed value and boolean context
| Reported by: | Tim Martin | Owned by: | Tim Martin |
|---|---|---|---|
| Component: | Template system | Version: | 1.10 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
I have the template
x={{x}}
y={{y}}
x|default_if_none:y={{x|default_if_none:y}}
{% if x|default_if_none:y %}
x|default_if_none:y is apparently True
{% endif %}
If x is unset (a missing variable in the template context) and y is set to True, then this prints:
x= y=True x|default_if_none:y = x|default_if_none:y is apparently True
This indicates that x:default_if_none:y evaluates to True in the boolean context, but doesn't print a value when evaluated directly.
Change History (4)
comment:1 by , 9 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:2 by , 9 years ago
comment:3 by , 9 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:4 by , 9 years ago
| Resolution: | → invalid |
|---|---|
| Status: | assigned → closed |
Apparently this is intentional behaviour, as documented here.
Note:
See TracTickets
for help on using tickets.
My original thought was to fix this in preparation for fixing #24977 (since I'll need to regularise this behaviour anyway, and it would make it clearer to fix the bugs independently). However, I don't think it's possible to do this without a hacky workaround. I'll close this when I've fixed #24977.