Skip to content

Commit

Permalink
fix(xpansion): turn "yearly-weights" and "additional-constraints" fie…
Browse files Browse the repository at this point in the history
…lds into mandatory fields
  • Loading branch information
laurent-laporte-pro committed Jan 4, 2024
1 parent f1da33f commit d2b2985
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 11 additions & 5 deletions antarest/study/business/xpansion_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,20 @@ class UpdateXpansionSettings(XpansionSettings, metaclass=AllOptionalMetaclass):
# note: for some reason, the alias is not taken into account when using the metaclass,
# so we have to redefine the fields with the alias.

yearly_weights: t.Optional[str] = Field( # type: ignore
None,
# On the other hand, we make these fields mandatory, because there is an anomaly on the front side:
# When the user does not select any file, the front sends a request without the "yearly-weights"
# or "additional-constraints" field, instead of sending the field with an empty value.
# This is not a problem as long as the front sends a request with all the fields (PUT case),
# but it is a problem for partial requests (PATCH case).

yearly_weights: str = Field(
"",
alias="yearly-weights",
description="Yearly weights file",
)

additional_constraints: t.Optional[str] = Field( # type: ignore
None,
additional_constraints: str = Field(
"",
alias="additional-constraints",
description="Additional constraints file",
)
Expand Down Expand Up @@ -702,7 +708,7 @@ def list_root_files(self, study: Study) -> t.List[str]:
root_files = [
key
for key, node in t.cast(FolderNode, file_study.tree.get_node(["user", "expansion"])).build().items()
if key not in registered_filenames and type(node) != BucketNode
if key not in registered_filenames and not isinstance(node, BucketNode)
]
return root_files

Expand Down
8 changes: 1 addition & 7 deletions antarest/study/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,7 @@
should_study_be_denormalized,
upgrade_study,
)
from antarest.study.storage.utils import (
assert_permission,
get_start_date,
is_managed,
remove_from_cache,
study_matcher,
)
from antarest.study.storage.utils import assert_permission, get_start_date, is_managed, remove_from_cache, study_matcher
from antarest.study.storage.variantstudy.model.command.icommand import ICommand
from antarest.study.storage.variantstudy.model.command.replace_matrix import ReplaceMatrix
from antarest.study.storage.variantstudy.model.command.update_comments import UpdateComments
Expand Down

0 comments on commit d2b2985

Please sign in to comment.