-
Notifications
You must be signed in to change notification settings - Fork 570
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 Avoid creating repository when it exists on remote #900
Conversation
The documentation is not available anymore as the PR was closed or merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also tests? :D
src/huggingface_hub/repository.py
Outdated
try: | ||
_ = HfApi().repo_info(f"{namespace}/{repo_id}") | ||
except HTTPError: | ||
self.client.create_repo( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm very confused, why would clone_from
create a repo remotely under any circumstances?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because link given to clone_from
might not be valid (there might not be a repository in remote under given namespace). Maybe it's better if I put a warning saying the remote repository doesn't exist instead. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's complicated. I really don't think it's appropriate for clone_from
to create anything. It should raise an error if the remote repository doesn't exist. Fixing it would be backward incompatible, but I think we can think of it as a bugfix. WDYT @LysandreJik ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized there are many tests that will fail and we'll break backwards compatibility if we change behavior of clone_from
to only clone remote repository, I also thought that it was only used to clone existing repository when creating repository on local. pinging @LysandreJik about why the design is that way 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(ok apparently you left a comment but I didn't see it bcs I didn't refresh the page lol)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(i agree that Repository clone_from shouldn't create a repo)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(can't find at the moment the past discussion with a potential explicit Repository.create() -> Repository
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I also think that clone_from
shouldn't create the repository if it doesn't exist, it isn't really its place to do so. I wouldn't say removing it is a bugfix as when I implemented it I shared it as such, but we can deprecate it for sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I say we merge this and then deprecate it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM!
Super weird thing
But when I run the test I've written (below) I still get the same error.
I have other stuff to do so will leave this for monday. |
"I can do following (which was my original problem) with no issue." |
@osanseviero yup I'm sure (I uninstalled and installed again) When I test this in a separate script, the repo is created remotely and is cloned well (when we instantiate Repository) that I can see there's README file of space which is the behavior we want here. |
This seems to be passing the tests now 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to merge and deprecate in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Only left a comment regarding space_sdk
.
src/huggingface_hub/repository.py
Outdated
try: | ||
_ = HfApi().repo_info(f"{namespace}/{repo_id}") | ||
except HTTPError: | ||
self.client.create_repo( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM!
src/huggingface_hub/repository.py
Outdated
token=token, | ||
repo_type=self.repo_type, | ||
exist_ok=True, | ||
private=self.private, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this also need a space_sdk
in case the repository in question is a space? i.e., if the repo is a space that doesn't exist, it'll try to create it but fail at doing so.
As we're deprecating, maybe that's intended and we keep that use-case as it is (i.e., not working)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will raise a ValueError
in case someone tries to create Space that doesn't exist because otherwise I have to add space_sdk
as a class attribute to Repository
(we're later deprecating the repository creation in clone_from
anyway so there's no point to add that). I'll add two tests, one for model repo and one for Space repo to see if the error is raised. We can merge tomorrow ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds great, thank you @merveenoyan!
Please do not review I know what the problem with tests is :D |
I added three tests:
|
Tests are not passing because moon-landing staging is down 😅 |
@merveenoyan it seems you're using an outdated version of
@SBrandeis, @XciD, would you have why we're getting errors 500 on the temp_repo_url = create_repo(
repo_id=f"temp",
token=token,
repo_type="space",
space_sdk="streamlit"
) I tried with both |
could this be related to new spaces infra @christophe-rannou |
@LysandreJik I just created a repo using the CLI with success. Maybe there's an issue with your token ? |
@christophe-rannou the token is that of the CI, we're using the same token for all CI. Were you on the production endpoint or the staging endpoint? |
Production one, it's the staging one that is not working ? |
Seems related to CI, will investigate. |
This one fails
|
This exact test fails on cf https://github.com/huggingface/huggingface_hub/runs/6882266625?check_suite_focus=true |
@LysandreJik sure! |
Was this supposed to be merged? As @LysandreJik mentioned, I think we should add the flag/decorator to skip the test so the tests are not failing ( |
No problem @osanseviero, I opened a PR to fix the problem there: #908 But now we have another problem with our CI because of the new datasets release, so waiting until that is fixed to merge it. |
About the spaces bug, we found it. |
Fixed |
* fix for spaces * fix for spaces * removed creating repository and added warning * revert my changes * added tests * removed debugger 😐 * fixed repository removal * Added tests and error * import pytest * fixed tests * fixed tests * style * removed repo removal * make style * fixed test with Lysandres patch * added fix
* added autoeval fields to repocard types * modified test, linted * Fix typo (#902) * Refine 404 errors (#878) * Add errors * Style * Review * hf_hub_download support * Errors for hf_hub_download * Typo * Handle 401 error * Tests for 401 error * Typo * Review comments * added documentation for the repocard change in repocard, updated metadata_eval_result, added documentation * 🏗 Use `hub-ci` for tests (#898) * 🏗 Use `hub-ci` for tests cc @XciD * 🩹 Also update URL for staging mode * ✅ 401 is raised when the user is not authenticated * 🗑 Deprecare `identical_ok` * Longer deprecation period * ✅ Fix the last failing test * Warning match docstring * FIX Avoid creating repository when it exists on remote (#900) * fix for spaces * fix for spaces * removed creating repository and added warning * revert my changes * added tests * removed debugger 😐 * fixed repository removal * Added tests and error * import pytest * fixed tests * fixed tests * style * removed repo removal * make style * fixed test with Lysandres patch * added fix * Remove deprecations (#910) * Remove deprecations * Typo * Update src/huggingface_hub/README.md Co-authored-by: Julien Chaumond <julien@huggingface.co> Co-authored-by: Julien Chaumond <julien@huggingface.co> * Add request ID to all requests (#909) * Add request ID to all requests * Typo * Typo * Review comments * Update src/huggingface_hub/utils/_errors.py Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> * Invert deprecation for create_repo (#912) * Invert deprecation for create_repo * Set to 0.10 * Constant was accidentally removed during deprecation transition (#913) Co-authored-by: Lyle Nel <lyle@owlin.com> * Update src/huggingface_hub/repocard_types.py Co-authored-by: lewtun <lewis.c.tunstall@gmail.com> * Update repocard_types.py * Update repocard_types.py * reorded metadata_eval_request_docs, added metrics_config and metrics_verified to tests Co-authored-by: lsb <leebutterman@gmail.com> Co-authored-by: Lysandre Debut <lysandre.debut@reseau.eseo.fr> Co-authored-by: Simon Brandeis <33657802+SBrandeis@users.noreply.github.com> Co-authored-by: Merve Noyan <merveenoyan@gmail.com> Co-authored-by: Julien Chaumond <julien@huggingface.co> Co-authored-by: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> Co-authored-by: Lyle Nel <lyle-nel@users.noreply.github.com> Co-authored-by: Lyle Nel <lyle@owlin.com> Co-authored-by: lewtun <lewis.c.tunstall@gmail.com>
This PR partially fixes #672.
I observed that the following error pops up when I create a repository using huggingface API
create_repo
and then have a local repository cloning from the URL using a token (here)ValueError: No space_sdk provided. create_repo expects space_sdk to be one of ['gradio', 'streamlit', 'static'] when repo_type is 'space'
So I noticed the following block was causing the problem:
Only name being valid shouldn't be enough to create a repository, we have to check if the repository exists on remote so I added a small check on that (thanks @muellerzr for pointing out to particular HfApi function that does it).
With this,
space_sdk
error should be gone. I'll add test once @LysandreJik approves my logic in here.Also this is separate but IDK if it's good to have an attribute
clone_from
and theclone_from()
function. I can refactor couple of things I saw there that's not good to me as well.