Code

Opened 8 years ago

Closed 7 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
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@…> 8 years ago.

Download all attachments as: .zip

Change History (7)

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

comment:1 Changed 8 years ago by mattmcc

  • Summary changed from Template tags ifequal and ifnotequal throw exception if variable does not resolve. to [patch] Template tags ifequal and ifnotequal throw exception if variable does not resolve.

Add [patch] to summary

comment:2 Changed 8 years ago by adrian

  • Status changed from new to assigned

comment:3 Changed 8 years ago by adrian

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 7 years ago by SmileyChris

  • Needs tests set
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

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

  • Version changed from SVN to 0.91

This issue was resolved prior to 0.95.

comment:6 Changed 7 years ago by SmileyChris

  • Resolution set to fixed
  • Status changed from assigned to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.