@@ -50,8 +50,10 @@ def project_exists(response, project):
50
50
51
51
52
52
def model_exists (project , name , force , versionName = "latest" ):
53
- """Checks if model already exists in the same project and either raises an error or deletes
54
- the redundant model. If no project version is provided, the version is assumed to be "latest".
53
+ """
54
+ Checks if model already exists in the same project and either raises an error or
55
+ deletes the redundant model. If no project version is provided, the version is
56
+ assumed to be "latest".
55
57
56
58
Parameters
57
59
----------
@@ -62,14 +64,15 @@ def model_exists(project, name, force, versionName="latest"):
62
64
force : bool, optional
63
65
Sets whether to overwrite models with the same name upon upload.
64
66
versionName : str, optional
65
- Name of project version to check if a model of the same name already exists. Default
66
- value is "latest".
67
+ Name of project version to check if a model of the same name already exists.
68
+ Default value is "latest".
67
69
68
70
Raises
69
71
------
70
72
ValueError
71
- Model repository API cannot overwrite an already existing model with the upload model call.
72
- Alerts user of the force argument to allow multi-call API overwriting.
73
+ Model repository API cannot overwrite an already existing model with the upload
74
+ model call. Alerts user of the force argument to allow multi-call API
75
+ overwriting.
73
76
"""
74
77
project = mr .get_project (project )
75
78
projectId = project ["id" ]
@@ -80,12 +83,17 @@ def model_exists(project, name, force, versionName="latest"):
80
83
versionId = projectVersions [latestVersion ]["id" ]
81
84
else :
82
85
for version in projectVersions :
83
- if versionName is version ["name" ]:
86
+ if versionName == version ["name" ]:
84
87
versionId = version ["id" ]
85
88
break
86
- projectModels = mr .get (
87
- "/projects/{}/projectVersions/{}/models" .format (projectId , versionId )
88
- )
89
+ try :
90
+ projectModels = mr .get (
91
+ "/projects/{}/projectVersions/{}/models" .format (projectId , versionId )
92
+ )
93
+ except UnboundLocalError :
94
+ raise ValueError (
95
+ f"The project version { versionName } was not found in project { project } ."
96
+ )
89
97
90
98
for model in projectModels :
91
99
# Throws a TypeError if only one model is in the project
@@ -95,19 +103,19 @@ def model_exists(project, name, force, versionName="latest"):
95
103
mr .delete_model (model .id )
96
104
else :
97
105
raise ValueError (
98
- "A model with the same model name exists in project {}. Include the force=True argument to overwrite models with the same name." . format (
99
- project . name
100
- )
106
+ "A model with the same model name exists in project {}. "
107
+ "Include the force=True argument to overwrite models with the "
108
+ "same name." . format ( project . name )
101
109
)
102
110
except TypeError :
103
111
if projectModels ["name" ] == name :
104
112
if force :
105
113
mr .delete_model (projectModels .id )
106
114
else :
107
115
raise ValueError (
108
- "A model with the same model name exists in project {}. Include the force=True argument to overwrite models with the same name." . format (
109
- project . name
110
- )
116
+ "A model with the same model name exists in project {}. "
117
+ "Include the force=True argument to overwrite models with the "
118
+ "same name." . format ( project . name )
111
119
)
112
120
113
121
0 commit comments