Opened 11 years ago

Closed 9 years ago

#1672 closed defect (fixed)

[patch] Template tags ifequal and ifnotequal throw exception if variable does not resolve.

Reported by: evenson@… 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: UI/UX:

Description

  1. obj is an instance of a django model
  2. 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)

defaulttags.patch (1.0 KB) - added by Eric Evenson <evenson@…> 11 years ago.

Download all attachments as: .zip

Change History (7)

Changed 11 years ago by Eric Evenson <evenson@…>

Attachment: defaulttags.patch added

comment:1 Changed 11 years ago by Matt McClanahan

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.

Add [patch] to summary

comment:2 Changed 11 years ago by Adrian Holovaty

Status: newassigned

comment:3 Changed 11 years ago by Adrian Holovaty

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 Changed 10 years ago by Chris Beaven

Needs tests: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

comment:5 Changed 9 years ago by Matt McClanahan <cardinal@…>

Version: SVN0.91

This issue was resolved prior to 0.95.

comment:6 Changed 9 years ago by Chris Beaven

Resolution: fixed
Status: assignedclosed

Thanks Matt, let's just mark it as closed then.

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