{{{
@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)
--
Ticket URL: <https://code.djangoproject.com/ticket/33036>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* has_patch: 0 => 1
Comment:
PR: https://github.com/django/django/pull/14779
--
Ticket URL: <https://code.djangoproject.com/ticket/33036#comment:1>
* owner: nobody => Matt Westcott
* status: new => assigned
* type: Bug => Cleanup/optimization
* stage: Unreviewed => Accepted
Comment:
Thanks for the report.
--
Ticket URL: <https://code.djangoproject.com/ticket/33036#comment:2>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/33036#comment:3>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"5092f7247de8d3aa2fdb762e50f5ac2aa4e6f6e0" 5092f72]:
{{{
#!CommitTicketReference repository=""
revision="5092f7247de8d3aa2fdb762e50f5ac2aa4e6f6e0"
Fixed #33036 -- Made simple_tag()/inclusion_tag() with takes_context raise
TemplateSyntaxError when function has no parameters.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33036#comment:4>