diff --git a/antarest/study/business/model/link_model.py b/antarest/study/business/model/link_model.py index 8bb48af215..3d049b94ff 100644 --- a/antarest/study/business/model/link_model.py +++ b/antarest/study/business/model/link_model.py @@ -97,9 +97,7 @@ class FilterOption(EnumIgnoreCase): ANNUAL = "annual" -def validate_filters( - filter_value: t.Union[t.List[FilterOption], str], enum_cls: t.Type[FilterOption] -) -> t.List[FilterOption]: +def validate_filters(filter_value: t.List[FilterOption] | str, enum_cls: t.Type[FilterOption]) -> t.List[FilterOption]: if isinstance(filter_value, str): if not filter_value.strip(): return [] diff --git a/antarest/study/storage/variantstudy/model/command/remove_multiple_binding_constraints.py b/antarest/study/storage/variantstudy/model/command/remove_multiple_binding_constraints.py index 2863466707..36c97806ae 100644 --- a/antarest/study/storage/variantstudy/model/command/remove_multiple_binding_constraints.py +++ b/antarest/study/storage/variantstudy/model/command/remove_multiple_binding_constraints.py @@ -9,10 +9,12 @@ # SPDX-License-Identifier: MPL-2.0 # # This file is part of the Antares project. + import typing as t from typing_extensions import override +from antarest.core.exceptions import NoConstraintError from antarest.study.model import STUDY_VERSION_8_7 from antarest.study.storage.rawstudy.model.filesystem.config.binding_constraint import DEFAULT_GROUP from antarest.study.storage.rawstudy.model.filesystem.config.model import FileStudyTreeConfig @@ -40,16 +42,18 @@ def _apply_config(self, study_data: FileStudyTreeConfig) -> OutputTuple: # If at least one bc is missing in the database, we raise an error already_existing_ids = {binding.id for binding in study_data.bindings} missing_bc_ids = [id_ for id_ in self.ids if id_ not in already_existing_ids] + if missing_bc_ids: - return CommandOutput(status=False, message=f"Binding constraint not found: '{missing_bc_ids}'"), {} - return CommandOutput(status=True, message=f"Binding constraint removed"), {} + return CommandOutput(status=False, message=f"Binding constraints missing: {missing_bc_ids}"), {} + + return CommandOutput(status=True), {} @override def _apply(self, study_data: FileStudy, listener: t.Optional[ICommandListener] = None) -> CommandOutput: - command_output, _ = self._apply_config(study_data.config) - - if not command_output.status: - return command_output + try: + self._apply_config(study_data.config) + except NoConstraintError as e: + return CommandOutput(status=False, message=str(e)) binding_constraints = study_data.tree.get(["input", "bindingconstraints", "bindingconstraints"]) @@ -83,7 +87,7 @@ def _apply(self, study_data: FileStudy, listener: t.Optional[ICommandListener] = removed_groups = old_groups - new_groups remove_bc_from_scenario_builder(study_data, removed_groups) - return command_output + return CommandOutput(status=True, message="Binding constraints deleted successfully.") @override def to_dto(self) -> CommandDTO: diff --git a/antarest/study/storage/variantstudy/variant_study_service.py b/antarest/study/storage/variantstudy/variant_study_service.py index fc9d447ea0..c6b2f1fc06 100644 --- a/antarest/study/storage/variantstudy/variant_study_service.py +++ b/antarest/study/storage/variantstudy/variant_study_service.py @@ -15,7 +15,7 @@ import re import shutil import typing as t -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from functools import reduce from pathlib import Path from uuid import uuid4 @@ -237,7 +237,7 @@ def append_commands( study_version=str(command.study_version), # params.user cannot be None, since previous checks were successful user_id=params.user.id, # type: ignore - updated_at=datetime.utcnow(), + updated_at=datetime.now(timezone.utc), ) for i, command in enumerate(validated_commands) ] @@ -279,7 +279,7 @@ def replace_commands( version=command.version, study_version=str(command.study_version), user_id=params.user.id, # type: ignore - updated_at=datetime.utcnow(), + updated_at=datetime.now(timezone.utc), ) for i, command in enumerate(validated_commands) ] @@ -634,8 +634,8 @@ def create_variant_study(self, uuid: str, name: str, params: RequestParameters) parent_id=uuid, path=study_path, public_mode=study.public_mode, - created_at=datetime.utcnow(), - updated_at=datetime.utcnow(), + created_at=datetime.now(timezone.utc), + updated_at=datetime.now(timezone.utc), version=study.version, folder=(re.sub(study.id, new_id, study.folder) if study.folder is not None else None), groups=study.groups, # Create inherit_group boolean @@ -935,8 +935,8 @@ def copy( parent_id=src_meta.parent_id, path=study_path, public_mode=PublicMode.NONE if groups else PublicMode.READ, - created_at=datetime.utcnow(), - updated_at=datetime.utcnow(), + created_at=datetime.now(timezone.utc), + updated_at=datetime.now(timezone.utc), version=src_meta.version, groups=groups, snapshot=None, @@ -1206,8 +1206,8 @@ def _clear_all_snapshots(self) -> None: ) ) for variant in variant_list: - if variant.updated_at and variant.updated_at < datetime.utcnow() - self._retention_time: - if variant.last_access and variant.last_access < datetime.utcnow() - self._retention_time: + if variant.updated_at and variant.updated_at < datetime.now(timezone.utc) - self._retention_time: + if variant.last_access and variant.last_access < datetime.now(timezone.utc) - self._retention_time: self._variant_study_service.clear_snapshot(variant) def run_task(self, notifier: ITaskNotifier) -> TaskResult: