Do not fail on repo/bucket creation if HTTP 401 and already exists#4294
Merged
Conversation
|
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. |
Member
|
I guess I'll get a bot message in this PR when a new version is released and I'll be able to update the docs then? |
Collaborator
|
@coyotte508 yes! |
Contributor
|
This PR has been shipped as part of the v1.18.0 release. |
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.
To be merged instead of #4290
With the introduction of JWT tokens, it is possible to get a HTTP 401 on repo creation even if the user is authenticated and has correct rights to push to that repo. If the repo already exists and
exists_ok=Truehas been passed, let's not raise any error and continue normally.The auto-repo creation is common in the ecosystem (in
upload_folderbut also transformers/diffusers/etc. 'spush_to_hub) so an ad-hoc fix like in #4290 wouldn't be robust. The solution here fixes the problem insidecreate_repodirectly.EDIT: also added the fix to
create_bucketsince bucket support for "Trusted Publishers" is also on the roadmap ( https://github.com/huggingface-internal/moon-landing/pull/17449#issuecomment-4558854897).cc @coyotte508
Note
Low Risk
Narrow change to error handling when exist_ok=True; behavior only relaxes failures when the target already exists.
Overview
When
exist_ok=True,create_repoandcreate_bucketnow treat HTTP 401 like 403: if creation fails for auth reasons (e.g. JWT without create-repo/create-bucket scope, or no write on the namespace), they probe whether the repo/bucket already exists viarepo_info/bucket_infoand return normally instead of raising.This targets flows such as
upload_folderandpush_to_hubthat auto-create repos, where a 401 on create could wrongly fail even when the user can push to an existing repo. A comment typo in the bucket path was fixed (“Repo” → “Bucket”).Reviewed by Cursor Bugbot for commit 7eeca9a. Bugbot is set up for automated code reviews on this repo. Configure here.