Skip to content

Commit f9483cb

Browse files
committed
fixes update node's states
1 parent eafc2d3 commit f9483cb

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

packages/models-library/src/models_library/projects_nodes.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,22 @@ class NodeState(BaseModel):
177177

178178
model_config = ConfigDict(
179179
extra="forbid",
180-
populate_by_name=True,
180+
validate_by_alias=True,
181+
validate_by_name=True,
181182
json_schema_extra={
182183
"examples": [
184+
# example with alias name
183185
{
184186
"modified": True,
185187
"dependencies": [],
186188
"currentStatus": "NOT_STARTED",
187189
},
190+
# example with field name
191+
{
192+
"modified": True,
193+
"dependencies": [],
194+
"current_status": "NOT_STARTED",
195+
},
188196
{
189197
"modified": True,
190198
"dependencies": ["42838344-03de-4ce2-8d93-589a5dcdfd05"],

services/web/server/src/simcore_service_webserver/projects/_projects_service.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,15 +1962,15 @@ async def add_project_states_for_user(
19621962
node_id=NodeID(node_uuid),
19631963
)
19641964
if NodeID(node_uuid) in computational_node_states:
1965-
node_state = computational_node_states[NodeID(node_uuid)].model_copy(
1966-
update={"lock_state": node_lock_state}
1967-
)
1965+
computed_node_state = computational_node_states[
1966+
NodeID(node_uuid)
1967+
].model_copy(update={"lock_state": node_lock_state})
19681968
else:
19691969
# if the node is not in the computational state, we create a new one
19701970
service_is_running = node_lock_state and (
19711971
node_lock_state.status is NodeShareStatus.OPENED
19721972
)
1973-
node_state = NodeState(
1973+
computed_node_state = NodeState(
19741974
current_status=(
19751975
RunningState.STARTED
19761976
if service_is_running
@@ -1980,9 +1980,14 @@ async def add_project_states_for_user(
19801980
)
19811981

19821982
# upgrade the project
1983-
node.setdefault("state", {}).update(
1984-
node_state.model_dump(mode="json", by_alias=True, exclude_unset=True)
1983+
# NOTE: copy&dump step avoids both alias and field-names to be keys in the dict
1984+
# e.g. "current_status" and "currentStatus"
1985+
current_node_state = NodeState.model_validate(node.get("state", {}))
1986+
updated_node_state = current_node_state.model_copy(
1987+
update=computed_node_state.model_dump(mode="json", exclude_unset=True)
19851988
)
1989+
node["state"] = updated_node_state.model_dump(by_alias=True, exclude_unset=True)
1990+
19861991
if "progress" in node["state"] and node["state"]["progress"] is not None:
19871992
# ensure progress is a percentage
19881993
node["progress"] = round(node["state"]["progress"] * 100.0)

0 commit comments

Comments
 (0)