summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2021-05-17 21:53:21 +0200
committerCarlton Gibson <carlton.gibson@noumenal.es>2021-05-26 09:41:29 +0200
commit68357b2ca9e88c40fc00d848799813241be39129 (patch)
tree2d0b297e1af538d226fe3756b430682c499959ec
parent7e51893911237dfca9294e3ca12163ff813fb656 (diff)
downloaddjango-68357b2ca9e88c40fc00d848799813241be39129.tar.gz
Fixed #32744 -- Normalized to pathlib.Path in autoreloader check for template changes.
-rw-r--r--django/template/autoreload.py7
-rw-r--r--docs/releases/3.2.4.txt3
-rw-r--r--tests/template_tests/test_autoreloader.py20
3 files changed, 28 insertions, 2 deletions
diff --git a/django/template/autoreload.py b/django/template/autoreload.py
index 36952ef9aa..18570b5633 100644
--- a/django/template/autoreload.py
+++ b/django/template/autoreload.py
@@ -1,6 +1,9 @@
+from pathlib import Path
+
from django.dispatch import receiver
from django.template import engines
from django.template.backends.django import DjangoTemplates
+from django.utils._os import to_path
from django.utils.autoreload import (
autoreload_started, file_changed, is_django_path,
)
@@ -15,13 +18,13 @@ def get_template_directories():
if not isinstance(backend, DjangoTemplates):
continue
- items.update(backend.engine.dirs)
+ items.update(Path.cwd() / to_path(dir) for dir in backend.engine.dirs)
for loader in backend.engine.template_loaders:
if not hasattr(loader, 'get_dirs'):
continue
items.update(
- directory
+ Path.cwd() / to_path(directory)
for directory in loader.get_dirs()
if not is_django_path(directory)
)
diff --git a/docs/releases/3.2.4.txt b/docs/releases/3.2.4.txt
index 048eb8c385..372ed87517 100644
--- a/docs/releases/3.2.4.txt
+++ b/docs/releases/3.2.4.txt
@@ -22,3 +22,6 @@ Bugfixes
* Fixed a crash in Django 3.2 that could occur when running ``mod_wsgi`` with
the recommended settings while the Windows ``colorama`` library was installed
(:ticket:`32740`).
+
+* Fixed a bug in Django 3.2 that would trigger the auto-reloader for template
+ changes when directory paths were specified with strings (:ticket:`32744`).
diff --git a/tests/template_tests/test_autoreloader.py b/tests/template_tests/test_autoreloader.py
index 7af6729b38..d6ece4cc6d 100644
--- a/tests/template_tests/test_autoreloader.py
+++ b/tests/template_tests/test_autoreloader.py
@@ -64,6 +64,26 @@ class TemplateReloadTests(SimpleTestCase):
autoreload.reset_loaders()
self.assertEqual(mock_reset.call_count, 2)
+ @override_settings(
+ TEMPLATES=[{
+ 'DIRS': [
+ str(ROOT) + '/absolute_str',
+ 'template_tests/relative_str',
+ Path('template_tests/relative_path'),
+ ],
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ }]
+ )
+ def test_template_dirs_normalized_to_paths(self):
+ self.assertSetEqual(
+ autoreload.get_template_directories(),
+ {
+ ROOT / 'absolute_str',
+ Path.cwd() / 'template_tests/relative_str',
+ Path.cwd() / 'template_tests/relative_path',
+ }
+ )
+
@require_jinja2
@override_settings(INSTALLED_APPS=['template_tests'])