#34692: django.forms.get_default_renderer()'s template loader cache is not being
reset on autoloads.
-----------------------------------------+------------------------
               Reporter:  kukwaa         |          Owner:  nobody
                   Type:  Bug            |         Status:  new
              Component:  Uncategorized  |        Version:  4.2
               Severity:  Normal         |       Keywords:
           Triage Stage:  Unreviewed     |      Has patch:  0
    Needs documentation:  0              |    Needs tests:  0
Patch needs improvement:  0              |  Easy pickings:  0
                  UI/UX:  0              |
-----------------------------------------+------------------------
 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 simple 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()
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34692>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701891c5f222e-8e443355-7864-4659-9d48-893cd6107a31-000000%40eu-central-1.amazonses.com.

Reply via email to