#36728: Validate template tag context argument at definition time, rather than
compile time
-------------------------------------+-------------------------------------
Reporter: Jake | Owner: Jake Howard
Howard |
Type: | Status: assigned
Cleanup/optimization |
Component: Template | Version: dev
system |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
If a template tag is defined incorrectly, by not accepting a `context`
argument with `takes_context=True`:
{{{#!python
@register.simple_tag(takes_context=True)
def my_tag():
pass
}}}
An error is only raised when the template is compiled, rather than when
the tag is defined as someone may expect. This means there’s extra work
done at compile time, which is duplicated each time the tag is used,
across multiple templates.
Moving this validation to be done at definition time would likely improve
performance. Reading the function signature is already done at definition
time, so the performance improvement will likely only be checking the list
of arguments, but reporting the error earlier would probably also be a DX
improvement.
See also [
https://forum.djangoproject.com/t/validate-template-tag-context-
argument-at-definition-time-rather-than-compile-time/42553 forum thread].
--
Ticket URL: <
https://code.djangoproject.com/ticket/36728>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.