﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
33036	Custom tags with missing context param and no other params throw an unhelpful IndexError	Matt Westcott	Matt Westcott	"Given a `simple_tag` or `inclusion_tag` with `takes_context=True`, where the `context` param has been forgotten:

{{{
@register.simple_tag(takes_context=True)
def simple_tag_without_context_parameter(arg):
    return ""Expected result""
}}}
the `parse_bits` function checks for this case and throws an informative `TemplateSyntaxError`. However, in the case that the tag takes no other parameters:

{{{
@register.simple_tag(takes_context=True)
def simple_tag_no_params_without_context_parameter():
    return ""Expected result""
}}}
the checking code fails at the point where it looks at `params[0]`, throwing an opaque `IndexError` instead.

{{{
Traceback (most recent call last):
  File ""/Users/matthew/Development/tbx/wagtail/devscript/libs/django/tests/template_tests/test_custom.py"", line 179, in test_simple_tag_no_params_missing_context
    self.engine.from_string('{% load custom %}{% simple_tag_no_params_without_context_parameter %}')
  File ""/Users/matthew/Development/tbx/wagtail/devscript/libs/django/django/template/engine.py"", line 156, in from_string
    return Template(template_code, engine=self)
  File ""/Users/matthew/Development/tbx/wagtail/devscript/libs/django/django/template/base.py"", line 155, in __init__
    self.nodelist = self.compile_nodelist()
  File ""/Users/matthew/Development/tbx/wagtail/devscript/libs/django/django/template/base.py"", line 199, in compile_nodelist
    return parser.parse()
  File ""/Users/matthew/Development/tbx/wagtail/devscript/libs/django/django/template/base.py"", line 502, in parse
    raise self.error(token, e)
  File ""/Users/matthew/Development/tbx/wagtail/devscript/libs/django/django/template/base.py"", line 500, in parse
    compiled_result = compile_func(self, token)
  File ""/Users/matthew/Development/tbx/wagtail/devscript/libs/django/django/template/library.py"", line 119, in compile_func
    args, kwargs = parse_bits(
  File ""/Users/matthew/Development/tbx/wagtail/devscript/libs/django/django/template/library.py"", line 246, in parse_bits
    if params[0] == 'context':
IndexError: list index out of range
}}}

(PR to follow)"	Cleanup/optimization	closed	Template system	dev	Normal	fixed			Ready for checkin	1	0	0	0	0	0
