File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -2082,6 +2082,15 @@ def create_repo(
20822082 if exist_ok and err .response .status_code == 409 :
20832083 # Repo already exists and `exist_ok=True`
20842084 pass
2085+ elif exist_ok and err .response .status_code == 403 :
2086+ # No write permission on the namespace but repo might already exist
2087+ try :
2088+ self .repo_info (repo_id = repo_id , repo_type = repo_type , token = token )
2089+ if repo_type is None or repo_type == REPO_TYPE_MODEL :
2090+ return RepoUrl (f"{ self .endpoint } /{ repo_id } " )
2091+ return RepoUrl (f"{ self .endpoint } /{ repo_type } /{ repo_id } " )
2092+ except HfHubHTTPError :
2093+ raise
20852094 else :
20862095 raise
20872096
Original file line number Diff line number Diff line change @@ -478,6 +478,16 @@ def test_create_repo_org_token_none_fail(self):
478478 with patch .object (self ._api , "token" , None ): # no default token
479479 self ._api .create_repo (repo_id = repo_name ("org" ))
480480
481+ def test_create_repo_already_exists_but_no_write_permission (self ):
482+ # Create under other user namespace
483+ repo_id = self ._api .create_repo (repo_id = repo_name (), token = OTHER_TOKEN ).repo_id
484+
485+ # Try to create with our namespace -> should not fail as the repo already exists
486+ self ._api .create_repo (repo_id = repo_id , token = TOKEN , exist_ok = True )
487+
488+ # Clean up
489+ self ._api .delete_repo (repo_id = repo_id , token = OTHER_TOKEN )
490+
481491 @retry_endpoint
482492 def test_upload_buffer (self ):
483493 REPO_NAME = repo_name ("buffer" )
You can’t perform that action at this time.
0 commit comments