#34720: BaseReloader.watch_dir() incorrectly checks for existence of path
-----------------------------+---------------------------------------
     Reporter:  Josh Thomas  |                    Owner:  Josh Thomas
         Type:  Bug          |                   Status:  closed
    Component:  Utilities    |                  Version:  4.2
     Severity:  Normal       |               Resolution:  invalid
     Keywords:               |             Triage Stage:  Unreviewed
    Has patch:  1            |      Needs documentation:  0
  Needs tests:  0            |  Patch needs improvement:  0
Easy pickings:  0            |                    UI/UX:  0
-----------------------------+---------------------------------------

Comment (by Natalia Bidart):

 Replying to [comment:7 Mariusz Felisiak]:
 > I have doubts that there is anything to change. It was not crucial for
 `watch_dir()` method to check if the path exists. We added `try ...
 except` to avoid crashes related with an issue in Python run on some
 Docker images (check out #30647), IMO it's still not fixed.

 Following this [https://discuss.python.org/t/pathlib-absolute-vs-
 resolve/2573 Python discussion about Pathlib absolute() vs. resolve()], I
 think we should migrate from `absolute` to `resolve`. I agree with Simon
 in that, considering that the
 [https://docs.python.org/3/library/pathlib.html#pathlib.Path.resolve
 Python docs] say that in Python3.6 (and previous) `resolve` would raise
 `FileNotFoundError`, but in Python3.7 and newer it does not raise any
 error, and given that we dropped support for Python3.6, I think we should
 be able to safely replace `absolute` with `resolve` and also remove the
 `try...except`.

 In summary, I think we could make the following into a PR and push it
 forward:


 {{{
 diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py
 index 5b22aef2b1..e863efea44 100644
 --- a/django/utils/autoreload.py
 +++ b/django/utils/autoreload.py
 @@ -283,16 +283,7 @@ class BaseReloader:
          self._stop_condition = threading.Event()

      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
 +        path = Path(path).resolve()
          logger.debug("Watching dir %s with glob %s.", path, glob)
          self.directory_globs[path].add(glob)
 }}}

 Adding to the above, the same file has multiple occurrences of calls like
 this:

 {{{
 resolved_path = path.resolve().absolute()
 }}}

 with no guard nor `try...except`.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34720#comment:11>
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/0107018992acc1c5-54319a9c-2d60-4fec-b4a8-5b4343e6616e-000000%40eu-central-1.amazonses.com.

Reply via email to