#34720: BaseReloader.watch_dir() incorrectly checks for existence of path
-------------------------------+--------------------------------------
Reporter: Josh | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by Josh:
Old 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.
New 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. I'm not sure of the etiquette behind self-
assigning a ticket before it's been reviewed, so I'm just leaving it
unassigned for now.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/34720#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018965fcee5b-ed54fae5-3414-4f65-a2ca-2c598dca105f-000000%40eu-central-1.amazonses.com.