#34878 closed Bug (fixed)
Autoreload crashes with FORM_RENDERER="django.forms.renderers.TemplatesSetting".
Reported by: | danjac | Owned by: | danjac |
---|---|---|---|
Component: | Template system | Version: | 5.0 |
Severity: | Release blocker | Keywords: | |
Cc: | Priyank Panchal, Jannis Vajen | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description (last modified by )
Running Python 3.11 and Django 5.0a1.
I have the following settings:
DEBUG = True FORM_RENDERER = "django.forms.renderers.TemplatesSetting" TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", "DIRS": [BASE_DIR / "templates"], "OPTIONS": { "debug": True, "context_processors": [ "django.template.context_processors.debug", "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.template.context_processors.i18n", "django.template.context_processors.media", "django.template.context_processors.static", "django.template.context_processors.tz", "django.contrib.messages.context_processors.messages", ], }, } ]
This causes the development server (i.e. manage.py runserver) to crash whenever a template is saved:
File "python-path/lib/python3.11/site-packages/django/template/autoreload.py", line 60, in template_changed reset_loaders() File "python-path/lib/python3.11/site-packages/django/template/autoreload.py", line 42, in reset_loaders backend = get_default_renderer().engine ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'TemplatesSetting' object has no attribute 'engine'
Change History (10)
comment:1 by , 14 months ago
Description: | modified (diff) |
---|
comment:2 by , 14 months ago
Cc: | added |
---|---|
Severity: | Normal → Release blocker |
Summary: | Setting FORM_RENDERER="django.forms.renderers.TemplatesSetting" causes template autoreload to crash → Autoreload crashes with FORM_RENDERER="django.forms.renderers.TemplatesSetting". |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:3 by , 14 months ago
Cc: | added |
---|
comment:4 by , 14 months ago
Easy pickings: | set |
---|
The following could be a regression test:
-
tests/template_tests/test_autoreloader.py
diff --git a/tests/template_tests/test_autoreloader.py b/tests/template_tests/test_autoreloader.py index 4fd7549a70..91ef94406c 100644
a b 1 1 from pathlib import Path 2 2 from unittest import mock 3 3 4 from django.forms.renderers import get_default_renderer 4 5 from django.template import autoreload 5 6 from django.test import SimpleTestCase, override_settings 6 7 from django.test.utils import require_jinja2 … … class TemplateReloadTests(SimpleTestCase): 68 69 self.assertIs(autoreload.template_changed(None, template_path), True) 69 70 mock_loader_reset.assert_called_once() 70 71 72 @override_settings(FORM_RENDERER="django.forms.renderers.TemplatesSetting") 73 @mock.patch("django.template.loaders.cached.Loader.reset") 74 def test_form_template_reset_template_change_no_djangotemplates( 75 self, mock_loader_reset, 76 ): 77 get_default_renderer.cache_clear() 78 template_path = Path(__file__).parent / "templates" / "index.html" 79 self.assertIs(autoreload.template_changed(None, template_path), True) 80 mock_loader_reset.assert_not_called() 81 get_default_renderer.cache_clear() 82 71 83 @mock.patch("django.forms.renderers.get_default_renderer") 72 84 def test_form_template_reset_non_template_change(self, mock_renderer): 73 85 self.assertIsNone(autoreload.template_changed(None, Path(__file__)))
comment:6 by , 14 months ago
Has patch: | set |
---|
comment:7 by , 14 months ago
Patch needs improvement: | set |
---|
comment:8 by , 14 months ago
Owner: | changed from | to
---|---|
Patch needs improvement: | unset |
Status: | new → assigned |
Triage Stage: | Accepted → Ready for checkin |
Note:
See TracTickets
for help on using tickets.
Thanks for the report. Would you like to prepare a patch? (a regression test is required, sth similar to the
template_tests.test_autoreloader.TemplateReloadTests.test_form_template_reset_template_change_reset_call
but with changedFORM_RENDERER
).The following works for me:
django/template/autoreload.py
backend = get_default_renderer().engineisinstance(backend, DjangoTemplates):backend.engine.template_loaders:Regression in 439242c5943e16dd5a3a68fadac76e5e723eb323.