Skip to content

fix(pickle): match cache-file events by name so waiters wake under watchdog 7 - #408

Open
marziomont wants to merge 2 commits into
python-cachier:masterfrom
marziomont:fix/watchdog-7-pattern-match
Open

marziomont wants to merge 2 commits into
python-cachier:masterfrom
marziomont:fix/watchdog-7-pattern-match

Conversation

@marziomont

Copy link
Copy Markdown

Problem

watchdog 7.0.0 changed PatternMatchingEventHandler to match patterns with PurePath.full_match() instead of PurePath.match(). full_match matches against the whole path, so the pickle core's "*" + filename pattern no longer matches an absolute event path such as /cache/dir/.module.func:

PurePath("/cache/dir/.module.func").match("*.module.func")       # True  (watchdog 6)
PurePath("/cache/dir/.module.func").full_match("*.module.func")  # False (watchdog 7)

A caller that finds an entry being calculated by another thread or process waits for the cache file to change. Under watchdog 7 the handler never fires, and with no wait_for_calc_timeout the waiter hangs forever.

cachier requires watchdog>=2.3.1 with no upper bound, so a fresh install picks up 7.x. uv.lock pins watchdog 6.0.0, which is why CI hasn't caught it.

Fix

CacheChangeHandler now subclasses FileSystemEventHandler and dispatches only the events whose source or destination file name equals the cache file's name. It ignores directory events. This matches by name instead of by glob, so it behaves the same under every watchdog version.

Tests

A new parametrized test checks the handler against full-path events: modified, created, a move onto the file, a sibling .lock file, another function's cache file, and a directory event.

Pickle core tests on Linux (Python 3.13, in Docker):

watchdog 6.0.0 watchdog 7.0.0
master 13 passed 5 failed (the 2 existing being-calculated tests + 3 new)
this PR 13 passed 13 passed

…tchdog 7

watchdog 7 matches PatternMatchingEventHandler patterns against the whole
path (PurePath.full_match), so the "*" + filename pattern never matched an
absolute event path. A caller waiting on an entry being calculated by
another thread or process never saw the change and hung forever.
@marziomont
marziomont requested a review from shaypal5 as a code owner November 3, 2026 11:09

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant