Opened 18 years ago

Closed 18 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 Holovaty
Component: Template system Version: dev
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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

Download all attachments as: .zip

Change History (4)

by Gary Wilson <gary.wilson@…>, 18 years ago

Attachment: 3465.diff added

a patch with some regression tests

by Gary Wilson <gary.wilson@…>, 18 years ago

Attachment: 3465_2.diff added

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

comment:1 by Gary Wilson <gary.wilson@…>, 18 years ago

Has patch: set
Triage Stage: UnreviewedAccepted

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

comment:2 by Jacob, 18 years ago

Resolution: fixed
Status: newclosed

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

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