Opened 20 years ago
Closed 18 years ago
#1672 closed defect (fixed)
[patch] Template tags ifequal and ifnotequal throw exception if variable does not resolve.
| Reported by: | Owned by: | Adrian Holovaty | |
|---|---|---|---|
| Component: | Template system | Version: | 0.91 |
| Severity: | minor | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | yes | Patch needs improvement: | yes |
| Easy pickings: | no | UI/UX: | no |
Description
- obj is an instance of a django model
- utility is a foreign key field in obj with null=True and blank=True.
{% ifequal obj.get_utility.abbr 'PG&E' %} ... {% endifequal %}
If utility_id is null in the db this throws a VariableDoesNotExist exception that does not get caught. I propose changing this case so ifequal fails and ifnotequal passes. This would be a simple change in django.core.template.defaulttags.IfEqualNode.render().
Attachments (1)
Change History (7)
by , 20 years ago
| Attachment: | defaulttags.patch added |
|---|
comment:1 by , 19 years ago
| Summary: | Template tags ifequal and ifnotequal throw exception if variable does not resolve. → [patch] Template tags ifequal and ifnotequal throw exception if variable does not resolve. |
|---|
comment:2 by , 19 years ago
| Status: | new → assigned |
|---|
comment:3 by , 19 years ago
This seems to be a problem with resolve_variable rather than ifequal. This unit test confirms the bug:
'ifequal11': ("{% ifequal a.method3.foo 'bar' %}yes{% else %}no{% endifequal %}", {'a': SomeClass()}, 'no'),
comment:4 by , 19 years ago
| Needs tests: | set |
|---|---|
| Patch needs improvement: | set |
| Triage Stage: | Unreviewed → Accepted |
comment:6 by , 18 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Thanks Matt, let's just mark it as closed then.
Note:
See TracTickets
for help on using tickets.
Add [patch] to summary