Skip to content

Make filter_repo_objects pattern matching case-sensitive on all platforms - #4435

Merged
Wauplin merged 3 commits into
huggingface:mainfrom
Sreekant13:fix/filter-repo-objects-case-sensitivity
Jun 29, 2026
Merged

Wauplin merged 3 commits into
huggingface:mainfrom
Sreekant13:fix/filter-repo-objects-case-sensitivity

Conversation

@Sreekant13

@Sreekant13 Sreekant13 commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes #4434.

filter_repo_objects matched allow_patterns / ignore_patterns with fnmatch.fnmatch, which applies os.path.normcase — so matching was case-insensitive on Windows but case-sensitive on Linux/macOS. Since these patterns are matched against case-sensitive Hub paths, the same call could return different files depending on the client OS (e.g. snapshot_download(..., allow_patterns=["*.PDF"])).

This switches to fnmatch.fnmatchcase, which performs the same wildcard matching without OS-dependent case normalization, making behavior consistent on all platforms. Adds a regression test and fixes an inconsistent docstring example.

Note: this is a behavior change on Windows (matching becomes case-sensitive). I believe consistent, case-sensitive matching is the correct behavior for Hub paths, but happy to gate it behind an option instead if you'd prefer.


Note

Medium Risk
Changes cross-platform filtering behavior for downloads and repo uploads on Windows; Linux/macOS users with case-mismatched patterns may see fewer matches than before on those OSes only if they relied on accidental case-insensitivity.

Overview
filter_repo_objects now matches allow_patterns and ignore_patterns with fnmatch.fnmatchcase instead of fnmatch, so wildcard filtering is case-sensitive on every platform (aligned with case-sensitive Hub paths). On Windows this is a behavior change: patterns like *.PDF no longer match file.pdf.

Docs and the path-filtering example are updated to describe case-sensitive matching. A regression test covers allow/ignore case sensitivity (issue #4434).

Reviewed by Cursor Bugbot for commit 46ba478. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread tests/test_utils_paths.py Resolved

@Wauplin Wauplin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a TIL for me, good catch 🤗

Comment thread tests/test_utils_paths.py Resolved
@bot-ci-comment

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@Wauplin
Wauplin merged commit b1f2bc0 into huggingface:main Jun 29, 2026
21 of 22 checks passed
@Sreekant13

Copy link
Copy Markdown
Contributor Author

Thanks for the quick review and merge! Learned the fnmatch/normcase quirk myself digging into this 🙂

@Sreekant13
Sreekant13 deleted the fix/filter-repo-objects-case-sensitivity branch June 29, 2026 08:06
@huggingface-hub-bot

Copy link
Copy Markdown
Contributor

This PR has been shipped as part of the v1.22.0 release.

CalamitousFelicitousness added a commit to vladmandic/sdnext that referenced this pull request Jul 8, 2026
diffusers pipeline downloads build subfolder config.json allow-patterns
with os.path.join, and huggingface_hub>=1.22 matches patterns with
fnmatchcase which does not normalize path separators
(huggingface/huggingface_hub#4435). On windows the resulting backslash
patterns match nothing, so per-component config.json files are never
downloaded and the incomplete snapshot still passes the diffusers
cache-completeness check, failing every subsequent load with
"no file named config.json".

Prefetch component configs with forward-slash patterns before pipeline
load. This covers all model families and also repairs snapshots already
broken by the bug on the next load attempt. No-op on linux, in offline
mode, and for local folder or single-file models.
liutyi pushed a commit to liutyi/sdnext that referenced this pull request Jul 8, 2026
diffusers pipeline downloads build subfolder config.json allow-patterns
with os.path.join, and huggingface_hub>=1.22 matches patterns with
fnmatchcase which does not normalize path separators
(huggingface/huggingface_hub#4435). On windows the resulting backslash
patterns match nothing, so per-component config.json files are never
downloaded and the incomplete snapshot still passes the diffusers
cache-completeness check, failing every subsequent load with
"no file named config.json".

Prefetch component configs with forward-slash patterns before pipeline
load. This covers all model families and also repairs snapshots already
broken by the bug on the next load attempt. No-op on linux, in offline
mode, and for local folder or single-file models.
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.

filter_repo_objects pattern matching is case-insensitive on Windows but case-sensitive on Linux

2 participants