Skip to content

Do not fail on repo/bucket creation if HTTP 401 and already exists#4294

Merged
Wauplin merged 2 commits into
mainfrom
do-not-fail-on-repo-creation-401-if-exists
May 29, 2026
Merged

Do not fail on repo/bucket creation if HTTP 401 and already exists#4294
Wauplin merged 2 commits into
mainfrom
do-not-fail-on-repo-creation-401-if-exists

Conversation

@Wauplin

@Wauplin Wauplin commented May 29, 2026

Copy link
Copy Markdown
Collaborator

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=True has been passed, let's not raise any error and continue normally.

The auto-repo creation is common in the ecosystem (in upload_folder but also transformers/diffusers/etc. 's push_to_hub) so an ad-hoc fix like in #4290 wouldn't be robust. The solution here fixes the problem inside create_repo directly.

EDIT: also added the fix to create_bucket since 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_repo and create_bucket now 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 via repo_info / bucket_info and return normally instead of raising.

This targets flows such as upload_folder and push_to_hub that 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.

@Wauplin Wauplin changed the title Do not fail on repo creation if HTTP 401 but repo already exists Do not fail on repo/bucket creation if HTTP 401 and already exists May 29, 2026
@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.

@coyotte508 coyotte508 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ah yes cleaner x)

@hanouticelina hanouticelina 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.

Looks good!

@Wauplin Wauplin merged commit 9c0c8c1 into main May 29, 2026
23 of 26 checks passed
@Wauplin Wauplin deleted the do-not-fail-on-repo-creation-401-if-exists branch May 29, 2026 17:39
@coyotte508

coyotte508 commented Jun 2, 2026

Copy link
Copy Markdown
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?

@hanouticelina

Copy link
Copy Markdown
Collaborator

@coyotte508 yes!

@huggingface-hub-bot

Copy link
Copy Markdown
Contributor

This PR has been shipped as part of the v1.18.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.

3 participants