Opened 8 years ago

Closed 8 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 Tim Martin, 8 years ago

Owner: changed from nobody to Tim Martin
Status: newassigned

comment:2 by Tim Martin, 8 years ago

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.

comment:3 by Tim Graham, 8 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Tim Martin, 8 years ago

Resolution: invalid
Status: assignedclosed

Apparently this is intentional behaviour, as documented here.

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