Opened 16 months ago
Last modified 15 months ago
#34692 closed Bug
django.forms.renderers.get_default_renderer()'s template loader cache is not being reset on autoloads. — at Version 1
Reported by: | Andrew | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | 4.2 |
Severity: | Normal | Keywords: | |
Cc: | David Smith | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Whenever a template file changes,
django.template.autoreload.template_changed() is called, which in turn calls
django.template.autoreload.reset_loaders(), which clears the template cache in every backend.engine's template loaders.
However, Django's renderer for Forms uses forms.renderers.get_default_renderer(), which returns a mixin that has its own engine instance, and therefore its own loaders (and template caches). This engine is never reset on autoloads. This means that any changes to a template that is referenced as part of, EG "Form.template_name", is never refreshed on changes. The entire runserver process must be restarted for any templates cached through forms.renders to be reloaded. This is tedious and does not match the behavior seen by non-form cached templates.
A crude fix can be demonstrated by changing reset_loaders() to the following:
def reset_loaders(): for backend in engines.all(): if not isinstance(backend, DjangoTemplates): continue for loader in backend.engine.template_loaders: loader.reset() # this code is new: reset the form renderer's template cache as well from django.forms.renderers import get_default_renderer for loader in get_default_renderer().engine.engine.template_loaders: loader.reset()
Change History (1)
comment:1 by , 16 months ago
Description: | modified (diff) |
---|---|
Summary: | django.forms.get_default_renderer()'s template loader cache is not being reset on autoloads. → django.forms.renderers.get_default_renderer()'s template loader cache is not being reset on autoloads. |