Code

Opened 7 years ago

Closed 7 years ago

#3465 closed (fixed)

template variable list-index lookup on an unsubscriptable object raises TypeError

Reported by: Gary Wilson <gary.wilson@…> Owned by: adrian
Component: Template system Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

For example, if the template variable "foobar" with value of None is passed to a template that uses:

{{ foobar.13 }}

The following traceback is produced

Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/django/template/__init__.py" in render_node
  718. result = node.render(context)
File "/usr/lib/python2.4/site-packages/django/template/__init__.py" in render
  768. output = self.filter_expression.resolve(context)
File "/usr/lib/python2.4/site-packages/django/template/__init__.py" in resolve
  561. obj = resolve_variable(self.var, context)
File "/usr/lib/python2.4/site-packages/django/template/__init__.py" in resolve_variable
  667. current = current[int(bits[0])]

  TypeError at /it/
  unsubscriptable object

The expected result would be for {{ foobar.13 }} to fail silently.

Attachments (2)

3465.diff (2.6 KB) - added by Gary Wilson <gary.wilson@…> 7 years ago.
a patch with some regression tests
3465_2.diff (3.2 KB) - added by Gary Wilson <gary.wilson@…> 7 years ago.
fixed a couple of spelling errors and added comments to one of the tests

Download all attachments as: .zip

Change History (4)

Changed 7 years ago by Gary Wilson <gary.wilson@…>

a patch with some regression tests

Changed 7 years ago by Gary Wilson <gary.wilson@…>

fixed a couple of spelling errors and added comments to one of the tests

comment:1 Changed 7 years ago by Gary Wilson <gary.wilson@…>

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

I'll let someone else review and mark as ready for checkin.

comment:2 Changed 7 years ago by jacob

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

(In [4639]) Fixed #3465: template variable lookups like {{ foobar.13 }} now (correctly) fail silently on unsubscriptable objects. Thanks, Gary Wilson.

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.