Opened 10 years ago

Closed 10 years ago

#23122 closed Bug (wontfix)

simple_tag should ignore undefined arguments to be consistent with template language

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 (last modified by Tim Graham)

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 (1)

comment:1 by Tim Graham, 10 years ago

Description: modified (diff)
Resolution: wontfix
Status: newclosed

I disagree as the trend I've observed is to make the template language fail more loudly, not less so. If you strongly disagree, please bring it up on the DevelopersMailingList. Thanks!

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