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

fs.exists(hub_model_id, refresh=True) does not work correctly after deleting a repository #2552

Open
MoritzLaurer opened this issue Sep 18, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@MoritzLaurer
Copy link
Contributor

Describe the bug

The following code outputs "True" twice, even though the repo is deleted. See this internal thread for details.

Reproduction

from huggingface_hub import HfApi, HfFileSystem
import time

api = HfApi()
hfs = HfFileSystem()
hub_model_id = "MoritzLaurer/test-repo"

api.create_repo(hub_model_id, repo_type='model')
print(hfs.exists(hub_model_id, refresh=True))
time.sleep(5)
api.delete_repo(repo_id=hub_model_id, repo_type="model")
time.sleep(5)
print(hfs.exists(hub_model_id, refresh=True))
# output True, True

Logs

No response

System info

huggingfac_hub==0.25.0
@MoritzLaurer MoritzLaurer added the bug Something isn't working label Sep 18, 2024
@MoritzLaurer
Copy link
Contributor Author

In case someone finds this issue later: the current recommended approach is using api.repo_exists instead of hfs.exists. HfApi is generally more used and better maintained than HfFileSystem so we recommend checking the docs for HfApi first.

This works correctly:

from huggingface_hub import HfApi, HfFileSystem
import time

api = HfApi()
hfs = HfFileSystem()
hub_model_id = "MoritzLaurer/test-repo"

api.create_repo(hub_model_id, repo_type='model')
print(api.repo_exists(repo_id=hub_model_id))
time.sleep(5)
api.delete_repo(repo_id=hub_model_id, repo_type="model")
time.sleep(5)
print(api.repo_exists(repo_id=hub_model_id))

@Wauplin
Copy link
Contributor

Wauplin commented Sep 18, 2024

Thanks for reporting @MoritzLaurer. This is indeed a bug in HfFileSystem implementation (not correctly refreshing the cache in this case).
@hanouticelina would you like to have a look when you have some time? (not urgent). It'll require to dive a bit in the fsspec internals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants