Fix offline simulation with huggingface_hub 1.27 - #8414
Open
hanouticelina wants to merge 2 commits into
Open
Conversation
Patch the client factory as well, so a client rebuilt mid-retry is also the mock.
|
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. |
hanouticelina
marked this pull request as ready for review
August 7, 2026 12:56
Contributor
Author
|
✅ looks good to me |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Surfaced by the
huggingface_hubv1.27.0.rc0 RC test branch, where 6 tests intests/test_load.pyfail: ci-test-huggingface-hub-1.27.0.rc0-release.They're all offline-simulation tests, and the failures are a test-harness issue rather than a regression in
huggingface_hub:test_offline_dataset_module_factory→'datasets.packaged_modules.text.text' != 'datasets.packaged_modules.cache.cache'test_offline_dataset_module_factory_with_capital_letters_in_name→ same, withcsv.csvtest_load_dataset_from_hub/test_load_dataset_namespace→DatasetNotFoundErrorinstead of the expectedConnectionErrortest_load_dataset_cached_from_hub[True/False]→'Using the latest cached version of the dataset'never loggedRoot cause
offline()patches the module globalhuggingface_hub.utils._http._GLOBAL_CLIENTwith a mock raisinghttpx.ConnectError.Since huggingface/huggingface_hub#4614,
_http_backoff_basefetches the client on every attempt instead of once before the retry loop (a closedhttpx.Clientcan't be reused).close_session()is called onhttpx.ConnectErrorand sets_GLOBAL_CLIENT = None, so:ConnectError→close_session()wipes the patched globalget_session(), seesNone, and rebuilds a real client via_GLOBAL_CLIENT_FACTORYWhich is exactly what the CI logs show — one
Retrying in 1s [Retry 1/5]line, then the test proceeding as if online.Minimal reproducer, patching
_GLOBAL_CLIENTwith a raising mock and callinghttp_backoff("HEAD", ...):Fix
Patch
_GLOBAL_CLIENT_FACTORYalongside_GLOBAL_CLIENT, so a client rebuilt mid-retry is the mock as well._GLOBAL_CLIENT_FACTORYhas existed sincehuggingface_hubv1.0, so it's safe under the existingIS_HF_HUB_1_xbranch. The<1.0branch is unchanged.Testing
Against
huggingface_hubmain(1.27.0.dev0):(the 6 failing tests plus 3 parametrized siblings)
And against
huggingface_hub==1.26.1, to confirm no backward-compat break:Draft for now — opening it so the fix is ready when you bump to 1.27.