Skip to content

Commit 4d6449e

Browse files
orffelixxm
authored andcommitted
[2.2.x] Fixed #30647 -- Fixed crash of autoreloader when extra directory cannot be resolved.
Backport of fc75694 from master.
1 parent 61d4a15 commit 4d6449e

4 files changed

Lines changed: 19 additions & 4 deletions

File tree

django/utils/autoreload.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,15 @@ def __init__(self):
235235

236236
def watch_dir(self, path, glob):
237237
path = Path(path)
238-
if not path.is_absolute():
239-
raise ValueError('%s must be absolute.' % path)
238+
try:
239+
path = path.absolute()
240+
except FileNotFoundError:
241+
logger.debug(
242+
'Unable to watch directory %s as it cannot be resolved.',
243+
path,
244+
exc_info=True,
245+
)
246+
return
240247
logger.debug('Watching dir %s with glob %s.', path, glob)
241248
self.directory_globs[path].add(glob)
242249

django/utils/translation/reloader.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ def watch_for_translation_changes(sender, **kwargs):
1313
directories.extend(Path(config.path) / 'locale' for config in apps.get_app_configs())
1414
directories.extend(Path(p) for p in settings.LOCALE_PATHS)
1515
for path in directories:
16-
absolute_path = path.absolute()
17-
sender.watch_dir(absolute_path, '**/*.mo')
16+
sender.watch_dir(path, '**/*.mo')
1817

1918

2019
def translation_file_changed(sender, file_path, **kwargs):

docs/releases/2.2.4.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ Bugfixes
2121

2222
* Fixed a regression in Django 2.2 where auto-reloader crashes if a file path
2323
contains nulls characters (``'\x00'``) (:ticket:`30506`).
24+
25+
* Fixed a regression in Django 2.2 where auto-reloader crashes if a translation
26+
directory cannot be resolved (:ticket:`30647`).

tests/utils_tests/test_autoreload.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,12 @@ def test_watch_with_single_file(self):
515515
watched_files = list(self.reloader.watched_files())
516516
self.assertIn(self.existing_file, watched_files)
517517

518+
def test_watch_dir_with_unresolvable_path(self):
519+
path = Path('unresolvable_directory')
520+
with mock.patch.object(Path, 'absolute', side_effect=FileNotFoundError):
521+
self.reloader.watch_dir(path, '**/*.mo')
522+
self.assertEqual(list(self.reloader.directory_globs), [])
523+
518524
def test_watch_with_glob(self):
519525
self.reloader.watch_dir(self.tempdir, '*.py')
520526
watched_files = list(self.reloader.watched_files())

0 commit comments

Comments
 (0)