summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/utils/autoreload.py2
-rw-r--r--docs/releases/2.2.2.txt4
-rw-r--r--tests/utils_tests/test_autoreload.py10
3 files changed, 15 insertions, 1 deletions
diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py
index 35952d5631..c959cd04ca 100644
--- a/django/utils/autoreload.py
+++ b/django/utils/autoreload.py
@@ -333,9 +333,9 @@ class StatReloader(BaseReloader):
while True:
for filepath, mtime in self.snapshot_files():
old_time = mtimes.get(filepath)
+ mtimes[filepath] = mtime
if old_time is None:
logger.debug('File %s first seen with mtime %s', filepath, mtime)
- mtimes[filepath] = mtime
continue
elif mtime > old_time:
logger.debug('File %s previous mtime: %s, current mtime: %s', filepath, old_time, mtime)
diff --git a/docs/releases/2.2.2.txt b/docs/releases/2.2.2.txt
index e95fa343fc..bcaac9f15d 100644
--- a/docs/releases/2.2.2.txt
+++ b/docs/releases/2.2.2.txt
@@ -28,3 +28,7 @@ Bugfixes
* Fixed a regression in Django 2.2 that caused a crash of auto-reloader when
an exception with custom signature is raised (:ticket:`30516`).
+
+* Fixed a regression in Django 2.2.1 where auto-reloader unnecessarily reloads
+ translation files multiple times when using ``StatReloader``
+ (:ticket:`30523`).
diff --git a/tests/utils_tests/test_autoreload.py b/tests/utils_tests/test_autoreload.py
index 82f7287fa8..56b03d40a6 100644
--- a/tests/utils_tests/test_autoreload.py
+++ b/tests/utils_tests/test_autoreload.py
@@ -656,6 +656,16 @@ class StatReloaderTests(ReloaderTests, IntegrationTests):
# Shorten the sleep time to speed up tests.
self.reloader.SLEEP_TIME = 0.01
+ @mock.patch('django.utils.autoreload.StatReloader.notify_file_changed')
+ def test_tick_does_not_trigger_twice(self, mock_notify_file_changed):
+ with mock.patch.object(self.reloader, 'watched_files', return_value=[self.existing_file]):
+ ticker = self.reloader.tick()
+ next(ticker)
+ self.increment_mtime(self.existing_file)
+ next(ticker)
+ next(ticker)
+ self.assertEqual(mock_notify_file_changed.call_count, 1)
+
def test_snapshot_files_ignores_missing_files(self):
with mock.patch.object(self.reloader, 'watched_files', return_value=[self.nonexistent_file]):
self.assertEqual(dict(self.reloader.snapshot_files()), {})