Opened 16 months ago

Last modified 16 months ago

#34720 closed Bug

Path checking in BaseReloader.watch_dir() incorrectly checks for existence of path — at Initial Version

Reported by: Josh Thomas Owned by: nobody
Component: Utilities Version: 4.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Within the watch_dir method in django.utils.autoreload.BaseReloader, the path is checked by calling on the absolute method on the Path object:

def watch_dir(self, path, glob):
    path = Path(path)
    try:
        path = path.absolute()
    except FileNotFoundError:
        logger.debug(
            "Unable to watch directory %s as it cannot be resolved.",
            path,
            exc_info=True,
        )
        return
    logger.debug("Watching dir %s with glob %s.", path, glob)
    self.directory_globs[path].add(glob)

Except absolute doesn't raise, it just returns the absolute path. Should be changed to an if check on path.exists():

Python 3.11.4 (main, Jul 17 2023, 15:40:49) [GCC 9.4.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.14.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from pathlib import Path

In [2]: Path('/home/josh/projects/django/nonexistent').absolute()
Out[2]: PosixPath('/home/josh/projects/django/nonexistent')

In [3]: Path('/home/josh/projects/django/nonexistent').exists()
Out[3]: False

Willing to prepare a patch.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top