diff --git a/antarest/launcher/service.py b/antarest/launcher/service.py index 824bfc75b0..ee193cadd8 100644 --- a/antarest/launcher/service.py +++ b/antarest/launcher/service.py @@ -228,7 +228,7 @@ def run_study( job_uuid = self._generate_new_id() logger.info(f"New study launch (study={study_uuid}, job_id={job_uuid})") study_info = self.study_service.get_study_information(uuid=study_uuid, params=params) - solver_version = study_version or study_info.version.__format__(format_spec="ddd") + solver_version = study_version or study_info.version.__str__() self._assert_launcher_is_initialized(launcher) assert_permission( diff --git a/antarest/study/business/areas/st_storage_management.py b/antarest/study/business/areas/st_storage_management.py index da4d99c231..0c150b3e95 100644 --- a/antarest/study/business/areas/st_storage_management.py +++ b/antarest/study/business/areas/st_storage_management.py @@ -394,7 +394,7 @@ def update_storages_props( # Convert the DTO to a configuration object and update the configuration file. properties = create_st_storage_config( - study.version, **new_cluster.model_dump(by_alias=False, exclude_none=True) + StudyVersion.parse(study.version), **new_cluster.model_dump(by_alias=False, exclude_none=True) ) path = _STORAGE_LIST_PATH.format(area_id=area_id, storage_id=storage_id) cmd = UpdateConfig( diff --git a/antarest/study/business/areas/thermal_management.py b/antarest/study/business/areas/thermal_management.py index daafde3608..a9c5bb924b 100644 --- a/antarest/study/business/areas/thermal_management.py +++ b/antarest/study/business/areas/thermal_management.py @@ -463,7 +463,7 @@ def validate_series(self, study: Study, area_id: str, cluster_id: str) -> bool: lower_cluster_id = cluster_id.lower() thermal_cluster_path = Path(f"input/thermal/series/{area_id}/{lower_cluster_id}") series_path = [thermal_cluster_path / "series"] - if StudyVersion(study.version) >= 870: + if StudyVersion.parse(study.version) >= 870: series_path.append(thermal_cluster_path / "CO2Cost") series_path.append(thermal_cluster_path / "fuelCost") diff --git a/antarest/study/model.py b/antarest/study/model.py index ba4b6603d0..9c80c32b7e 100644 --- a/antarest/study/model.py +++ b/antarest/study/model.py @@ -359,8 +359,8 @@ class StudyMetadataDTO(BaseModel): folder: t.Optional[str] = None tags: t.List[str] = [] - @field_serializer('version', when_used='json') - def serialize_version(self, version: StudyVersion): + @field_serializer('version') + def serialize_version(self, version: StudyVersion) -> int: return version.__int__() @field_validator("horizon", mode="before") diff --git a/antarest/study/storage/rawstudy/model/filesystem/config/files.py b/antarest/study/storage/rawstudy/model/filesystem/config/files.py index df1c32fb22..249560556e 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/config/files.py +++ b/antarest/study/storage/rawstudy/model/filesystem/config/files.py @@ -199,7 +199,7 @@ def _parse_version(path: Path) -> StudyVersion: inside_root_path=Path("study.antares"), file_type=FileType.SIMPLE_INI, ) - version = study_info.get("antares", {}).get("version", -1) + version = study_info.get("antares", {}).get("version", 0) return StudyVersion.parse(version) diff --git a/antarest/study/storage/rawstudy/model/filesystem/config/model.py b/antarest/study/storage/rawstudy/model/filesystem/config/model.py index ef92d19a19..aea8bb0640 100644 --- a/antarest/study/storage/rawstudy/model/filesystem/config/model.py +++ b/antarest/study/storage/rawstudy/model/filesystem/config/model.py @@ -15,7 +15,7 @@ from pathlib import Path from antares.study.version import StudyVersion -from pydantic import BaseModel, Field, model_validator +from pydantic import BaseModel, Field, model_validator, field_serializer, field_validator from antarest.core.utils.utils import DTO from antarest.study.business.enum_ignore_case import EnumIgnoreCase @@ -318,6 +318,15 @@ class FileStudyTreeConfigDTO(BaseModel): enr_modelling: str = str(EnrModelling.AGGREGATED) zip_path: t.Optional[Path] = None + @field_serializer('version') + def serialize_version(self, version: StudyVersion) -> int: + return version.__int__() + + @field_validator("version", mode="before") + def _validate_version(cls, v: t.Any) -> StudyVersion: + return StudyVersion.parse(v) + + @staticmethod def from_build_config( config: FileStudyTreeConfig, diff --git a/tests/cache/test_local_cache.py b/tests/cache/test_local_cache.py index a643be4c62..3242d92533 100644 --- a/tests/cache/test_local_cache.py +++ b/tests/cache/test_local_cache.py @@ -28,7 +28,7 @@ def test_lifecycle(): study_path=Path("somepath"), path=Path("somepath"), study_id="", - version=StudyVersion.parse(-1), + version=StudyVersion.parse(0), areas={ "a1": Area( name="a1", diff --git a/tests/cache/test_redis_cache.py b/tests/cache/test_redis_cache.py index f17faa6f9a..f5fe9c37a3 100644 --- a/tests/cache/test_redis_cache.py +++ b/tests/cache/test_redis_cache.py @@ -27,7 +27,7 @@ def test_lifecycle(): study_path=Path("somepath"), path=Path("somepath"), study_id="", - version=StudyVersion.parse(-1), + version=StudyVersion.parse(0), areas={ "a1": Area( name="a1", diff --git a/tests/storage/business/test_raw_study_service.py b/tests/storage/business/test_raw_study_service.py index 9364edfa14..2e9bb25c5a 100644 --- a/tests/storage/business/test_raw_study_service.py +++ b/tests/storage/business/test_raw_study_service.py @@ -621,7 +621,7 @@ def test_check_and_update_study_version_in_database(tmp_path: Path) -> None: assert raw_study.version == "100" - raw_study = RawStudy(id=name, workspace="foo", path=str(study_path), version="100") + raw_study = RawStudy(id=name, workspace="foo", path=str(study_path), version="42") file_study_tree = Mock() file_study_tree.get.return_value = {"version": 42} diff --git a/tests/storage/business/test_study_version_upgrader.py b/tests/storage/business/test_study_version_upgrader.py index 4fa7e940ec..979f38d064 100644 --- a/tests/storage/business/test_study_version_upgrader.py +++ b/tests/storage/business/test_study_version_upgrader.py @@ -124,15 +124,15 @@ def test_fails_because_of_versions_asked(tmp_path: Path): with zipfile.ZipFile(path_study) as zip_output: zip_output.extractall(path=study_dir) # Try to upgrade with an unknown version - with pytest.raises(InvalidUpgrade, match="Cannot downgrade from version '7.2' to '6'"): + with pytest.raises(InvalidUpgrade, match="Cannot downgrade from version '720' to '600'"): StudyUpgrader(study_dir, "600").upgrade() # Try to upgrade with the current version - with pytest.raises(InvalidUpgrade, match="Your study is already in version '7.2'"): + with pytest.raises(InvalidUpgrade, match="Your study is already in version '720'"): StudyUpgrader(study_dir, "720").upgrade() # Try to upgrade with an old version with pytest.raises( InvalidUpgrade, - match="Cannot downgrade from version '7.2' to '7.1'", + match="Cannot downgrade from version '720' to '710'", ): StudyUpgrader(study_dir, "710").upgrade() # Try to upgrade with a version that does not exist diff --git a/tests/storage/repository/filesystem/config/test_config_files.py b/tests/storage/repository/filesystem/config/test_config_files.py index a0fdf6d4f5..77ae462678 100644 --- a/tests/storage/repository/filesystem/config/test_config_files.py +++ b/tests/storage/repository/filesystem/config/test_config_files.py @@ -81,7 +81,7 @@ def test_parse_output_parameters(study_path: Path) -> None: config = FileStudyTreeConfig( study_path=study_path, path=study_path, - version=-1, + version=0, store_new_set=True, study_id="id", output_path=study_path / "output", @@ -105,7 +105,7 @@ def test_parse_bindings(study_path: Path) -> None: config = FileStudyTreeConfig( study_path=study_path, path=study_path, - version=-1, + version=0, bindings=[ BindingConstraintDTO( id="bindA", @@ -154,7 +154,7 @@ def test_parse_outputs(study_path: Path) -> None: study_path=study_path, path=study_path, study_id="id", - version=-1, + version=0, output_path=study_path / "output", outputs={ "20201220-1456eco-hello": Simulation( @@ -271,7 +271,7 @@ def test_parse_area(study_path: Path) -> None: study_path=study_path, path=study_path, study_id="id", - version=-1, + version=0, output_path=study_path / "output", areas={ "fr": Area( @@ -307,7 +307,7 @@ def test_parse_area__extra_area(study_path: Path) -> None: study_path=study_path, path=study_path, study_id="id", - version=-1, + version=0, output_path=study_path / "output", areas={ "fr": Area(