Skip to content
Snippets Groups Projects
Commit aaa18478 authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Model-loading always returns {'model_id': _} when successfuly

parent c8c58fcd
No related branches found
No related tags found
No related merge requests found
......@@ -23,9 +23,9 @@ def load_ilastik_model(model_class: ilm.IlastikImageToImageModel, project_file:
:return: dict containing model's ID
"""
if not duplicate:
existing_model = session.find_param_in_loaded_models('project_file', project_file, is_path=True)
if existing_model is not None:
return existing_model
existing_model_id = session.find_param_in_loaded_models('project_file', project_file, is_path=True)
if existing_model_id is not None:
return {'model_id': existing_model_id}
try:
result = session.load_model(model_class, {'project_file': project_file})
except (FileNotFoundError, ParameterExpectedError):
......
......@@ -171,20 +171,21 @@ class TestIlastikOverApi(TestServerBaseClass):
self.assertEqual(pathlib.Path(ilp_win), pathlib.Path(ilp_posx))
# load models with these paths
requests.put(
resp1 = requests.put(
self.uri + 'ilastik/px/load/',
params={
'project_file': ilp_win,
'duplicate': False,
},
)
requests.put(
resp2 = requests.put(
self.uri + 'ilastik/px/load/',
params={
'project_file': ilp_posx,
'duplicate': False,
},
)
self.assertEqual(resp1.json(), resp2.json())
# assert that only one copy of the model is loaded
resp_list_2 = requests.get(self.uri + 'models').json()
......
......@@ -127,7 +127,7 @@ class Session(object):
for k in self.models.keys()
}
def find_param_in_loaded_models(self, key: str, value: str, is_path=False) -> dict:
def find_param_in_loaded_models(self, key: str, value: str, is_path=False) -> str:
"""
Returns model_id of first model where key and value match with .params field, or None
:param is_path: uses platform-independent path comparison if True
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment