Opened 8 years ago
Last modified 8 years ago
#28172 new Bug
Prevent nonexistent template filter arguments from raising VariableDoesNotExist
Reported by: | Vlastimil Zíma | Owned by: | |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Someday/Maybe | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I'd like to fix the error reported in #13167. The main bug
from django.template import Context, Template Template('{{ foo|default:notreal }}').render(Context({'foo': ''}))
still raises VariableDoesNotExist
exception, which is completely unexpected from templates, as noted in closing comment ticket:13167#comment:20. I took me more than an hour before I found out how did it make the server error I investigated.
I know the original ticket was closed as wontfix, but I understood it was due to the effect the proposed change would have on if
tag. But there's another way - capture the exception in VariableNode
the similar way UnicodeDecodeError
is silenced. If I understood the code correctly, that would solve the problem for all template filters, but left template tags intact.
Change History (4)
comment:1 by , 8 years ago
Summary: | Non-existent arg passed to template filter raises VariableDoesNotExist (alternative solution) → Prevent nonexistent template filter arguments from raising VariableDoesNotExist |
---|---|
Triage Stage: | Unreviewed → Someday/Maybe |
comment:2 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 8 years ago
Alejandro, I don't think there's consensus to make this change (hence the ticket's Someday/Maybe status). Did you read the mailing list discussion linked from in comment 1?
comment:4 by , 8 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
I understand the "template errors don't raise exceptions" philosophy, however, I think changing the current behavior would be more error prone (e.g. typos in variable names go more easily undetected). I've started a django-developers thread to get other opinions.