From 6762e0b75b71d3f4cdbe89f88335de1ba9ce38cd Mon Sep 17 00:00:00 2001 From: Andrei Neagu Date: Fri, 20 Dec 2024 15:41:20 +0100 Subject: [PATCH 1/2] fixed issue --- packages/common-library/src/common_library/unset.py | 4 ++++ packages/common-library/tests/test_unset.py | 9 ++++++++- .../services/director_v2/_thin_client.py | 9 +++------ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/common-library/src/common_library/unset.py b/packages/common-library/src/common_library/unset.py index 3d4dfcbc947..6f635dfe643 100644 --- a/packages/common-library/src/common_library/unset.py +++ b/packages/common-library/src/common_library/unset.py @@ -10,3 +10,7 @@ class UnSet: def as_dict_exclude_unset(**params) -> dict[str, Any]: return {k: v for k, v in params.items() if not isinstance(v, UnSet)} + + +def as_dict_exclude_none(**params) -> dict[str, Any]: + return {k: v for k, v in params.items() if v is not None} diff --git a/packages/common-library/tests/test_unset.py b/packages/common-library/tests/test_unset.py index 0fece0d466c..624b2d9e12c 100644 --- a/packages/common-library/tests/test_unset.py +++ b/packages/common-library/tests/test_unset.py @@ -1,6 +1,6 @@ from typing import Any -from common_library.unset import UnSet, as_dict_exclude_unset +from common_library.unset import UnSet, as_dict_exclude_none, as_dict_exclude_unset def test_as_dict_exclude_unset(): @@ -13,3 +13,10 @@ def f( assert f(par1="hi") == {"par1": "hi"} assert f(par2=4) == {"par2": 4} assert f(par1="hi", par2=4) == {"par1": "hi", "par2": 4} + + # still expected behavior + assert as_dict_exclude_unset(par1=None) == {"par1": None} + + +def test_as_dict_exclude_none(): + assert as_dict_exclude_none(par1=None) == {} diff --git a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/director_v2/_thin_client.py b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/director_v2/_thin_client.py index 412e7377d19..d1bbd36aa14 100644 --- a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/director_v2/_thin_client.py +++ b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/director_v2/_thin_client.py @@ -2,7 +2,7 @@ from typing import cast from common_library.json_serialization import json_dumps -from common_library.unset import UnSet, as_dict_exclude_unset +from common_library.unset import as_dict_exclude_none from fastapi import FastAPI, status from httpx import Response, Timeout from models_library.api_schemas_dynamic_scheduler.dynamic_services import ( @@ -133,14 +133,11 @@ async def dynamic_service_retrieve( @retry_on_errors() @expect_status(status.HTTP_200_OK) async def get_dynamic_services( - self, - *, - user_id: UserID | None | UnSet = UnSet.VALUE, - project_id: ProjectID | None | UnSet = UnSet.VALUE, + self, *, user_id: UserID | None = None, project_id: ProjectID | None = None ) -> Response: return await self.client.get( "/dynamic_services", - params=as_dict_exclude_unset(user_id=user_id, project_id=project_id), + params=as_dict_exclude_none(user_id=user_id, project_id=project_id), ) @retry_on_errors() From ecff50a7394a6ec04209b672c4d812a7d5ab0719 Mon Sep 17 00:00:00 2001 From: Andrei Neagu Date: Mon, 6 Jan 2025 14:34:43 +0100 Subject: [PATCH 2/2] rename module --- .../common-library/src/common_library/{unset.py => exclude.py} | 0 .../common-library/tests/{test_unset.py => test_exclude.py} | 2 +- .../services/director_v2/_thin_client.py | 2 +- .../server/src/simcore_service_webserver/folders/_folders_db.py | 2 +- .../src/simcore_service_webserver/projects/_folders_db.py | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) rename packages/common-library/src/common_library/{unset.py => exclude.py} (100%) rename packages/common-library/tests/{test_unset.py => test_exclude.py} (86%) diff --git a/packages/common-library/src/common_library/unset.py b/packages/common-library/src/common_library/exclude.py similarity index 100% rename from packages/common-library/src/common_library/unset.py rename to packages/common-library/src/common_library/exclude.py diff --git a/packages/common-library/tests/test_unset.py b/packages/common-library/tests/test_exclude.py similarity index 86% rename from packages/common-library/tests/test_unset.py rename to packages/common-library/tests/test_exclude.py index 624b2d9e12c..78f5712161e 100644 --- a/packages/common-library/tests/test_unset.py +++ b/packages/common-library/tests/test_exclude.py @@ -1,6 +1,6 @@ from typing import Any -from common_library.unset import UnSet, as_dict_exclude_none, as_dict_exclude_unset +from common_library.exclude import UnSet, as_dict_exclude_none, as_dict_exclude_unset def test_as_dict_exclude_unset(): diff --git a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/director_v2/_thin_client.py b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/director_v2/_thin_client.py index d1bbd36aa14..aef8823ce7d 100644 --- a/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/director_v2/_thin_client.py +++ b/services/dynamic-scheduler/src/simcore_service_dynamic_scheduler/services/director_v2/_thin_client.py @@ -1,8 +1,8 @@ import datetime from typing import cast +from common_library.exclude import as_dict_exclude_none from common_library.json_serialization import json_dumps -from common_library.unset import as_dict_exclude_none from fastapi import FastAPI, status from httpx import Response, Timeout from models_library.api_schemas_dynamic_scheduler.dynamic_services import ( diff --git a/services/web/server/src/simcore_service_webserver/folders/_folders_db.py b/services/web/server/src/simcore_service_webserver/folders/_folders_db.py index 38ad97f44ed..32ff9e4d3a5 100644 --- a/services/web/server/src/simcore_service_webserver/folders/_folders_db.py +++ b/services/web/server/src/simcore_service_webserver/folders/_folders_db.py @@ -10,7 +10,7 @@ import sqlalchemy as sa from aiohttp import web -from common_library.unset import UnSet, as_dict_exclude_unset +from common_library.exclude import UnSet, as_dict_exclude_unset from models_library.folders import ( FolderDB, FolderID, diff --git a/services/web/server/src/simcore_service_webserver/projects/_folders_db.py b/services/web/server/src/simcore_service_webserver/projects/_folders_db.py index d8c965be26b..d4fde1f5ce9 100644 --- a/services/web/server/src/simcore_service_webserver/projects/_folders_db.py +++ b/services/web/server/src/simcore_service_webserver/projects/_folders_db.py @@ -8,7 +8,7 @@ from datetime import datetime from aiohttp import web -from common_library.unset import UnSet, as_dict_exclude_unset +from common_library.exclude import UnSet, as_dict_exclude_unset from models_library.folders import FolderID from models_library.projects import ProjectID from models_library.users import UserID