Django

Code

Ticket #3465 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

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

Reported by: Gary Wilson <gary.wilson@gmail.com> Assigned to: adrian
Milestone: Component: Template system
Version: SVN Keywords:
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

3465.diff (2.6 kB) - added by Gary Wilson <gary.wilson@gmail.com> on 02/09/07 12:00:53.
a patch with some regression tests
3465_2.diff (3.2 kB) - added by Gary Wilson <gary.wilson@gmail.com> on 02/09/07 12:12:12.
fixed a couple of spelling errors and added comments to one of the tests

Change History

02/09/07 12:00:53 changed by Gary Wilson <gary.wilson@gmail.com>

  • attachment 3465.diff added.

a patch with some regression tests

02/09/07 12:12:12 changed by Gary Wilson <gary.wilson@gmail.com>

  • attachment 3465_2.diff added.

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

02/09/07 12:16:29 changed by Gary Wilson <gary.wilson@gmail.com>

  • needs_better_patch changed.
  • has_patch set to 1.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs changed.

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

02/27/07 14:25:27 changed by jacob

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #3465 (template variable list-index lookup on an unsubscriptable object raises TypeError)




Change Properties
Action