Opened 10 years ago

Last modified 10 years ago

#23122 closed Bug

simple_tag should ignore undefined arguments to be consistent with template language — at Initial Version

Reported by: adriannye@… Owned by: nobody
Component: Template system Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Template references to an undefined variable are silently replaced with the empty string:

{{ undefined_variable }}

is replaced by

But if that same variable is referenced as an argument to a templatetag that uses the simple_tag decorator,
it will return an exception:

{% my_simple_tag undefined_variable %}

raises an exception. This also happens if there are multiple arguments and any one of them is undefined.

The simple_tag decorator resolves all variables in the context using:

resolved_vars = [var.resolve(context) for var in self.vars_to_resolve]

It would be better if this code handled the variable consistently, so that users could switch back and forth from using a templatetag or not and see the same result. One way would be to replace the above code with the following:

resolved_vars = []
for var in self.vars_to_resolve:

try:

value = var.resolve(context)

except VariableDoesNotExist:

value = None

resolved_vars.append(value)

Change History (0)

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