Skip to content

Commit 2924476

Browse files
committed
Fix create_model_performance for single models with a project
1 parent 095d9ab commit 2924476

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

src/sasctl/_services/model_management.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -187,39 +187,35 @@ def create_performance_definition(
187187
% max_bins
188188
)
189189

190-
if not project and not models:
190+
# Separate single models from multiple models
191+
if not isinstance(models, list):
192+
models = [models]
193+
194+
if not project and not models[0]:
191195
raise ValueError(
192196
"No project or model specified for performance definition creation.\n"
193197
"Please specify at least one of the two values."
194198
)
195-
196199
# If no models were specified, search the supplied project for all models
197-
if not models:
200+
elif not models[0]:
198201
project = mr.get_project(project)
199202
models = mr.list_models(
200-
filter="eq(projectName, '{projectName}')".format(
201-
projectName=project.name
202-
)
203+
filter=f"eq(projectName, '{project.name}')"
203204
)
204-
205-
# Separate single models from multiple models
206-
if not isinstance(models, list):
207-
models = [models]
208-
if project:
209-
project = mr.get_project(project)
210-
project_models = mr.get(f'/projects/{project.id}/models')
211-
project_models = [m for m in project_models if m.name in models]
212-
models = project_models
213-
# Necessary to eventually provide variables to the performance definition
214-
models[0] = mr.get_model(project_models[0].id)
215205
else:
216-
# Collect all models into a list. This converts the PagedList response from mr.list_models to a normal list.
217206
for i, model in enumerate(models):
218207
models[i] = mr.get_model(model)
219-
project = mr.get_project(models[0].projectId)
208+
if project:
209+
project = mr.get_project(project)
210+
else:
211+
project = mr.get_project(models[0].projectId)
220212
# Ensures that all models are in the same project
221213
if not all([model.projectId == project.id for model in models]):
222-
raise ValueError("Not all models are contained within the same project. Try specifying a project.")
214+
raise ValueError(
215+
"Not all models are contained within the same project. Try "
216+
"specifying a project in the arguments and verify that all models"
217+
"are from the same project."
218+
)
223219

224220
# Performance data cannot be captured unless certain project properties have been configured.
225221
for required in ["targetVariable", "targetLevel"]:

0 commit comments

Comments
 (0)