Skip to content

Apply fsspec config in HfFileSystem metaclass#4062

Merged
Wauplin merged 1 commit intohuggingface:mainfrom
joaquinhuigomez:fix/hf-filesystem-fsspec-config
Apr 24, 2026
Merged

Apply fsspec config in HfFileSystem metaclass#4062
Wauplin merged 1 commit intohuggingface:mainfrom
joaquinhuigomez:fix/hf-filesystem-fsspec-config

Conversation

@joaquinhuigomez
Copy link
Copy Markdown
Contributor

@joaquinhuigomez joaquinhuigomez commented Apr 7, 2026

HfFileSystem's _Cached metaclass overrides fsspec.spec._Cached.__call__ but skips the apply_config call that upstream fsspec uses to read config values from environment variables and config files. As a result, HfFileSystem silently ignores fsspec config that works on every other filesystem backend.

This patch calls apply_config(cls, kwargs) at the start of __call__, matching upstream fsspec behavior.

Fixes #3996


Note

Medium Risk
Changes HfFileSystem instantiation/caching by applying fsspec env/config defaults before tokenization, which can alter cache keys and runtime options for existing users relying on implicit defaults.

Overview
Ensures HfFileSystem honors standard fsspec configuration (env vars / config files) by calling apply_config in the custom _Cached.__call__ before computing the instance cache token.

This aligns HfFileSystem behavior with upstream fsspec filesystems so default options from config are applied consistently when creating/reusing cached filesystem instances.

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

The HfFileSystem metaclass _Cached overrides fsspec.spec._Cached.__call__
but never calls apply_config, so fsspec config values (from environment
variables or config files) are silently dropped for HfFileSystem while
they work for every other fsspec filesystem.

Call apply_config on kwargs at the start of __call__, matching the
upstream fsspec._Cached behavior.

Fixes huggingface#3996
@Wauplin
Copy link
Copy Markdown
Contributor

Wauplin commented Apr 8, 2026

Hi @joaquinhuigomez, thanks for the PR! Do you have a minimal example showcasing the fix? i.e. a simple test that I could run both on main and on your branch to check it's correctly fixed

also cc @lhoestq for viz'

Copy link
Copy Markdown
Member

@lhoestq lhoestq left a comment

Choose a reason for hiding this comment

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

LGTM for consistency with fsspec

it means that fsspec config has precedence over huggingface_hub constants though but it makes sense imo (it's also the case for s3fs for example)

apply_config is also an old/mature function so I'm fine with using it as is

@Wauplin
Copy link
Copy Markdown
Contributor

Wauplin commented Apr 23, 2026

Thanks for the fix @joaquinhuigomez and thanks for reviewing @lhoestq! I'm fine with merging as soon as the CI is green :)

@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 9104623 into huggingface:main Apr 24, 2026
13 of 17 checks passed
@huggingface-hub-bot
Copy link
Copy Markdown
Contributor

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

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.

HfFileSystem is incompatible with fsspec's config

3 participants