Skip to content

Commit fc75694

Browse files
orffelixxm
authored andcommitted
Fixed #30647 -- Fixed crash of autoreloader when extra directory cannot be resolved.
1 parent fed5e19 commit fc75694

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
@@ -240,8 +240,15 @@ def __init__(self):
240240

241241
def watch_dir(self, path, glob):
242242
path = Path(path)
243-
if not path.is_absolute():
244-
raise ValueError('%s must be absolute.' % path)
243+
try:
244+
path = path.absolute()
245+
except FileNotFoundError:
246+
logger.debug(
247+
'Unable to watch directory %s as it cannot be resolved.',
248+
path,
249+
exc_info=True,
250+
)
251+
return
245252
logger.debug('Watching dir %s with glob %s.', path, glob)
246253
self.directory_globs[path].add(glob)
247254

django/utils/translation/reloader.py

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

2019

2120
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
@@ -499,6 +499,12 @@ def test_overlapping_glob_recursive(self, mocked_modules, notify_mock):
499499
class BaseReloaderTests(ReloaderTests):
500500
RELOADER_CLS = autoreload.BaseReloader
501501

502+
def test_watch_dir_with_unresolvable_path(self):
503+
path = Path('unresolvable_directory')
504+
with mock.patch.object(Path, 'absolute', side_effect=FileNotFoundError):
505+
self.reloader.watch_dir(path, '**/*.mo')
506+
self.assertEqual(list(self.reloader.directory_globs), [])
507+
502508
def test_watch_with_glob(self):
503509
self.reloader.watch_dir(self.tempdir, '*.py')
504510
watched_files = list(self.reloader.watched_files())

0 commit comments

Comments
 (0)