Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reloader exlude_patterns behavior differs for WatchdogReloaderLoop and StatReloaderLoop #2561

Closed
robnagler opened this issue Dec 26, 2022 · 2 comments

Comments

@robnagler
Copy link

Setting exclude_patterns to an absolute path, e.g. /home/me/bar/*, works fine with StatReloaderLoop, and fails to exclude paths with WatchdogReloaderLoop. The root cause is that WatchdogReloaderLoop uses watchdog which relies on pathlib.PurePath.match and StatReloaderLoop relies on `fnmatch. Here's a simple demonstration:

import fnmatch
assert fnmatch.fnmatch("/foo/bar/baz", "/foo/*")

import pathlib
assert pathlib.PurePosixPath("/foo/bar/baz").match("/foo/*"), "FAIL"

Pathlib's behavior is too strict for this particularly problem, since it matches from the right for relative paths and exact matches for absolute paths. fnmatch finds first match from the left.

The workaround is to disable the watchdog by passing reloader_type="stat" to run_simple.

Environment:

  • Python version: 3.7.2
  • Werkzeug version: 2.0.3
@davidism
Copy link
Member

davidism commented Feb 8, 2023

This sounds like a bug report for Watchdog, not Werkzeug. We don't appear to be calling PurePath.match in our reloader code, our code for exclude_patterns is the same between _find_stat_paths and _find_watchdog_paths, they both use fnmatch.

@davidism davidism closed this as completed Feb 8, 2023
@robnagler
Copy link
Author

You want to at least document the problem. It was tricky to track down.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants