Skip to content

Commit 3ef87d6

Browse files
use model_validate
1 parent 3dea491 commit 3ef87d6

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def to_simcore_runtime_docker_labels(self) -> dict[DockerLabelKey, str]:
143143
"""returns a dictionary of strings as required by docker"""
144144
return {
145145
to_simcore_runtime_docker_label_key(k): f"{v}"
146-
for k, v in sorted(self.model_copy().model_dump().items())
146+
for k, v in sorted(self.model_dump().items())
147147
}
148148

149149
@classmethod

services/director-v2/src/simcore_service_director_v2/modules/dynamic_sidecar/docker_compose_specs.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ def _update_paths_mappings(
128128
)
129129
env_vars["DY_SIDECAR_PATH_INPUTS"] = f"{path_mappings.inputs_path}"
130130
env_vars["DY_SIDECAR_PATH_OUTPUTS"] = f"{path_mappings.outputs_path}"
131-
env_vars[
132-
"DY_SIDECAR_STATE_PATHS"
133-
] = f"{json_dumps( { f'{p}' for p in path_mappings.state_paths } )}"
131+
env_vars["DY_SIDECAR_STATE_PATHS"] = (
132+
f"{json_dumps( { f'{p}' for p in path_mappings.state_paths } )}"
133+
)
134134

135135
service_content["environment"] = _EnvironmentSection.export_as_list(env_vars)
136136

@@ -241,15 +241,17 @@ def _update_container_labels(
241241
spec_service_key, default_limits
242242
)
243243

244-
label_keys = StandardSimcoreDockerLabels.model_construct(
245-
user_id=user_id,
246-
project_id=project_id,
247-
node_id=node_id,
248-
simcore_user_agent=simcore_user_agent,
249-
product_name=product_name,
250-
swarm_stack_name=swarm_stack_name,
251-
memory_limit=ByteSize(container_limits["memory"]),
252-
cpu_limit=container_limits["cpu"],
244+
label_keys = StandardSimcoreDockerLabels.model_validate(
245+
{
246+
"user_id": user_id,
247+
"project_id": project_id,
248+
"node_id": node_id,
249+
"simcore_user_agent": simcore_user_agent,
250+
"product_name": product_name,
251+
"swarm_stack_name": swarm_stack_name,
252+
"memory_limit": ByteSize(container_limits["memory"]),
253+
"cpu_limit": container_limits["cpu"],
254+
}
253255
)
254256
docker_labels = [
255257
f"{k}={v}" for k, v in label_keys.to_simcore_runtime_docker_labels().items()

services/director-v2/src/simcore_service_director_v2/utils/dask.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -315,17 +315,19 @@ def compute_task_labels(
315315
ValidationError
316316
"""
317317
product_name = run_metadata.get("product_name", UNDEFINED_DOCKER_LABEL)
318-
standard_simcore_labels = StandardSimcoreDockerLabels.model_construct(
319-
user_id=user_id,
320-
project_id=project_id,
321-
node_id=node_id,
322-
product_name=product_name,
323-
simcore_user_agent=run_metadata.get(
324-
"simcore_user_agent", UNDEFINED_DOCKER_LABEL
325-
),
326-
swarm_stack_name=UNDEFINED_DOCKER_LABEL, # NOTE: there is currently no need for this label in the comp backend
327-
memory_limit=node_requirements.ram,
328-
cpu_limit=node_requirements.cpu,
318+
standard_simcore_labels = StandardSimcoreDockerLabels.model_validate(
319+
{
320+
"user_id": user_id,
321+
"project_id": project_id,
322+
"node_id": node_id,
323+
"product_name": product_name,
324+
"simcore_user_agent": run_metadata.get(
325+
"simcore_user_agent", UNDEFINED_DOCKER_LABEL
326+
),
327+
"swarm_stack_name": UNDEFINED_DOCKER_LABEL, # NOTE: there is currently no need for this label in the comp backend
328+
"memory_limit": node_requirements.ram,
329+
"cpu_limit": node_requirements.cpu,
330+
}
329331
).to_simcore_runtime_docker_labels()
330332
return standard_simcore_labels | TypeAdapter(ContainerLabelsDict).validate_python(
331333
{
@@ -633,7 +635,7 @@ def check_if_cluster_is_able_to_run_pipeline(
633635

634636

635637
async def wrap_client_async_routine(
636-
client_coroutine: Coroutine[Any, Any, Any] | Any | None
638+
client_coroutine: Coroutine[Any, Any, Any] | Any | None,
637639
) -> Any:
638640
"""Dask async behavior does not go well with Pylance as it returns
639641
a union of types. this wrapper makes both mypy and pylance happy"""

0 commit comments

Comments
 (0)