Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX create_repo with exists_ok but no permission #1364

Merged
merged 6 commits into from
Mar 7, 2023

Conversation

Wauplin
Copy link
Contributor

@Wauplin Wauplin commented Feb 28, 2023

Corner case but used in a lot of integrations. Problem is when doing create_repo(..., exists_ok). If repo already exists, it's not supposed to raise an exception. However, if the repo exists but the user do not have permission on this namespace, a HTTP 403 is thrown. Since we catch only HTTP 409 conflict, the error is not caught.

With this PR, if we get an HTTP 403, we check if the repo exists or not before raising an exception. This is useful for third-party integrations having a "push_to_hub"-like method and create_pr=True. We do not want to throw an error on create repo since write permission will not be needed to create a PR.

See related slack thread (internal link) cc @thomasw21 @coyotte508

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Feb 28, 2023

The documentation is not available anymore as the PR was closed or merged.

@codecov
Copy link

codecov bot commented Mar 2, 2023

Codecov Report

Patch coverage: 62.50% and project coverage change: -0.01 ⚠️

Comparison is base (318f1be) 84.50% compared to head (35cc3b7) 84.50%.

❗ Current head 35cc3b7 differs from pull request most recent head 7287287. Consider uploading reports for the commit 7287287 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1364      +/-   ##
==========================================
- Coverage   84.50%   84.50%   -0.01%     
==========================================
  Files          48       48              
  Lines        4814     4820       +6     
==========================================
+ Hits         4068     4073       +5     
- Misses        746      747       +1     
Impacted Files Coverage Δ
src/huggingface_hub/hf_api.py 89.78% <62.50%> (-0.23%) ⬇️
src/huggingface_hub/commands/user.py 0.00% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@osanseviero osanseviero left a comment

Choose a reason for hiding this comment

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

Conceptual LGTM, but let's wait for @LysandreJik's review :)

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

Non-conceptual LGTM :)

@Wauplin Wauplin merged commit 4c0fcd1 into main Mar 7, 2023
@Wauplin Wauplin deleted the fix-create-repo-exist-ok-but-forbidden branch March 7, 2023 20:32
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.

None yet

4 participants