1
0
mirror of https://github.com/django/django.git synced 2024-12-25 10:35:48 +00:00

[5.0.x] Fixed #34878 -- Fixed autoreloader crash when FORM_RENDERER is set to TemplatesSetting.

Regression in 439242c594.

Backport of fe835c2355 from main
This commit is contained in:
Dan Jacob 2023-09-28 22:49:39 +03:00 committed by Mariusz Felisiak
parent 0f9d07398d
commit e60fe3bb05
2 changed files with 13 additions and 1 deletions

View File

@ -39,7 +39,7 @@ def reset_loaders():
for loader in backend.engine.template_loaders:
loader.reset()
backend = get_default_renderer().engine
backend = getattr(get_default_renderer(), "engine", None)
if isinstance(backend, DjangoTemplates):
for loader in backend.engine.template_loaders:
loader.reset()

View File

@ -1,6 +1,7 @@
from pathlib import Path
from unittest import mock
from django.forms.renderers import get_default_renderer
from django.template import autoreload
from django.test import SimpleTestCase, override_settings
from django.test.utils import require_jinja2
@ -68,6 +69,17 @@ class TemplateReloadTests(SimpleTestCase):
self.assertIs(autoreload.template_changed(None, template_path), True)
mock_loader_reset.assert_called_once()
@override_settings(FORM_RENDERER="django.forms.renderers.TemplatesSetting")
@mock.patch("django.template.loaders.cached.Loader.reset")
def test_form_template_reset_template_change_no_djangotemplates(
self, mock_loader_reset
):
self.addCleanup(get_default_renderer.cache_clear)
get_default_renderer.cache_clear()
template_path = Path(__file__).parent / "templates" / "index.html"
self.assertIs(autoreload.template_changed(None, template_path), True)
mock_loader_reset.assert_not_called()
@mock.patch("django.forms.renderers.get_default_renderer")
def test_form_template_reset_non_template_change(self, mock_renderer):
self.assertIsNone(autoreload.template_changed(None, Path(__file__)))