[Django] #36728: Validate template tag context argument at definition time, rather than compile time

1 view
Skip to first unread message

Django

unread,
4:20 AM (17 hours ago) 4:20 AM
to django-...@googlegroups.com
#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.

Django

unread,
11:26 AM (10 hours ago) 11:26 AM
to django-...@googlegroups.com
#36728: Validate template tag context argument at definition time, rather than
compile time
-------------------------------------+-------------------------------------
Reporter: Jake Howard | Owner: Jake
Type: | Howard
Cleanup/optimization | Status: assigned
Component: Template system | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* stage: Unreviewed => Accepted

Comment:

Thank you Jake! Once the fix is in place, I would like to see some
before/after benchmarks for the startup time to confirm the assumption
that this won't hurt it.
--
Ticket URL: <https://code.djangoproject.com/ticket/36728#comment:1>

Django

unread,
12:49 PM (9 hours ago) 12:49 PM
to django-...@googlegroups.com
#36728: Validate template tag context argument at definition time, rather than
compile time
-------------------------------------+-------------------------------------
Reporter: Jake Howard | Owner: Jake
Type: | Howard
Cleanup/optimization | Status: assigned
Component: Template system | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jake Howard):

* has_patch: 0 => 1

Comment:

[https://github.com/django/django/pull/20086 PR]

As mentioned in the PR description, because the majority of the work was
already being done eagerly, the performance benefit is likely to be within
margin of error for Python benchmarks (it's just a list member check).
Therefore, I've not done any benchmarks currently.
--
Ticket URL: <https://code.djangoproject.com/ticket/36728#comment:2>
Reply all
Reply to author
Forward
0 new messages