Skip to content

Commit

Permalink
fix(bc): sonar blocker fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoPascoli committed Jan 30, 2025
1 parent bd671ed commit 3776096
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
4 changes: 1 addition & 3 deletions antarest/study/business/model/link_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"])

Expand Down Expand Up @@ -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:
Expand Down
18 changes: 9 additions & 9 deletions antarest/study/storage/variantstudy/variant_study_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
]
Expand Down Expand Up @@ -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)
]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 3776096

Please sign in to comment.