From f3863c2a7e495a171cbd3510d2148624c9261f60 Mon Sep 17 00:00:00 2001 From: Laurent LAPORTE Date: Mon, 22 Apr 2024 20:58:06 +0200 Subject: [PATCH] fix(st-storage): turn `STStorageOutput` fields into optional fields --- antarest/study/business/areas/st_storage_management.py | 7 ++++--- tests/integration/study_data_blueprint/test_table_mode.py | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/antarest/study/business/areas/st_storage_management.py b/antarest/study/business/areas/st_storage_management.py index bb0987502c..373f8c3ea4 100644 --- a/antarest/study/business/areas/st_storage_management.py +++ b/antarest/study/business/areas/st_storage_management.py @@ -80,7 +80,7 @@ def to_config(self, study_version: t.Union[str, int]) -> STStorageConfigType: @camel_case_model -class STStorageOutput(STStorage880Config): +class STStorageOutput(STStorage880Config, metaclass=AllOptionalMetaclass, use_none=True): """ Model representing the form used to display the details of a short-term storage entry. """ @@ -236,7 +236,7 @@ def create_storage_output( cluster_id: str, config: t.Mapping[str, t.Any], ) -> "STStorageOutput": - obj = create_st_storage_config(study_version, **config, id=cluster_id) + obj = create_st_storage_config(study_version=study_version, **config, id=cluster_id) kwargs = obj.dict(by_alias=False) return STStorageOutput(**kwargs) @@ -357,11 +357,12 @@ def get_all_storages_props( except KeyError: raise STStorageConfigNotFound(path) from None + study_version = study.version storages_by_areas: t.MutableMapping[str, t.MutableMapping[str, STStorageOutput]] storages_by_areas = collections.defaultdict(dict) for area_id, cluster_obj in storages.items(): for cluster_id, cluster in cluster_obj.items(): - storages_by_areas[area_id][cluster_id] = create_storage_output(int(study.version), cluster_id, cluster) + storages_by_areas[area_id][cluster_id] = create_storage_output(study_version, cluster_id, cluster) return storages_by_areas diff --git a/tests/integration/study_data_blueprint/test_table_mode.py b/tests/integration/study_data_blueprint/test_table_mode.py index 84cd61df5b..15536b8426 100644 --- a/tests/integration/study_data_blueprint/test_table_mode.py +++ b/tests/integration/study_data_blueprint/test_table_mode.py @@ -594,6 +594,7 @@ def test_lifecycle__nominal( "id", "name", # Short-term storage fields + "enabled", # since v8.8 "group", "injectionNominalCapacity", "withdrawalNominalCapacity", @@ -670,6 +671,7 @@ def test_lifecycle__nominal( # "id": "siemens", # "name": "Siemens", "efficiency": 1, + "enabled": None, "group": "Battery", "initialLevel": 0.5, "initialLevelOptim": False, @@ -681,6 +683,7 @@ def test_lifecycle__nominal( # "id": "tesla", # "name": "Tesla", "efficiency": 0.75, + "enabled": None, "group": "Battery", "initialLevel": 0.89, "initialLevelOptim": False, @@ -692,6 +695,7 @@ def test_lifecycle__nominal( # "id": "storage3", # "name": "storage3", "efficiency": 1, + "enabled": None, "group": "Pondage", "initialLevel": 1, "initialLevelOptim": False, @@ -703,6 +707,7 @@ def test_lifecycle__nominal( # "id": "storage4", # "name": "storage4", "efficiency": 1, + "enabled": None, "group": "PSP_open", "initialLevel": 0.5, "initialLevelOptim": True,