Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#9290 closed (worksforme)

List index out of range when invalid template tag is used

Reported by: aneil Owned by: nobody
Component: Uncategorized Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Using an invalid template tag results in the generic 'list index out of range' error which doesn't show any information about the offending file or expression. E.g., if a template contains:

...
{% invalid_template_tag %} 
...

An error occurs at line 279 of django.template.__init__.py:

278   try:
279      compiled_result = compile_func(self, token)
280   except KeyError:
281      self.invalid_block_tag(token, command)
282   except TemplateSyntaxError, e:
283      if not self.compile_function_error(token,e):
291          raise

What seems to be happening is that self.invalid_block_tag(...) raises an error which gets caught by TemplateSyntaxError and which eventually leads to the generic 'list index out of range' error being reported in the Django error page.

This problem has also been reported to the BetterErrorMessages page.

Change History (2)

comment:1 by Badri, 16 years ago

Needs documentation: set
Resolution: worksforme
Status: newclosed
Triage Stage: UnreviewedAccepted
>>> from django import template
>>> s = u'<html> <h1>{% badri %} </h1></html>'
>>> t = template.Template(s)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.5/site-packages/django/template/__init__.py", line 166, in __init__
    self.nodelist = compile_string(template_string, origin)
  File "/usr/local/lib/python2.5/site-packages/django/template/__init__.py", line 187, in compile_string
    return parser.parse()
  File "/usr/local/lib/python2.5/site-packages/django/template/__init__.py", line 281, in parse
    self.invalid_block_tag(token, command)
  File "/usr/local/lib/python2.5/site-packages/django/template/__init__.py", line 333, in invalid_block_tag
    raise self.error(token, "Invalid block tag: '%s'" % command)
django.template.TemplateSyntaxError: Invalid block tag: 'badri'

comment:2 by Malcolm Tredinnick, 16 years ago

If the original reporter can still repeat this, please reopen, but include a short, complete template which demonstrates the problem and the full traceback that Django displays at the time (use the cut-and-paste view when copying the traceback). It's not clear from reading the code where the index error could be coming from and badri's example above shows that the simplest case doesn't trigger the problem. So if there's a generic error here, we need a lot more information to be able to replicate it.

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