Skip to content

Commit

Permalink
fix(api-bc): prevent null values for optional strings
Browse files Browse the repository at this point in the history
  • Loading branch information
hdinia committed Apr 3, 2024
1 parent 1f5f8a7 commit a6f2020
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions antarest/study/business/binding_constraint_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ def constraint_model_adapter(constraint: Mapping[str, Any], version: int) -> Con
"terms": constraint.get("terms", []),
}

# TODO: Implement a model for version-specific fields. Output filters are sent regardless of the version.
if version >= 840:
constraint_output["filter_year_by_year"] = constraint.get("filter_year_by_year") or constraint.get(
"filter-year-by-year", ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ class BindingConstraintProperties(BaseModel, extra=Extra.forbid, allow_populatio
enabled: bool = True
time_step: BindingConstraintFrequency = BindingConstraintFrequency.HOURLY
operator: BindingConstraintOperator = BindingConstraintOperator.EQUAL
comments: t.Optional[str] = None
filter_year_by_year: t.Optional[str] = None
filter_synthesis: t.Optional[str] = None
comments: t.Optional[str] = ""
filter_year_by_year: t.Optional[str] = ""
filter_synthesis: t.Optional[str] = ""


class BindingConstraintProperties870(BindingConstraintProperties):
group: t.Optional[str] = None
group: t.Optional[str] = "default"


class BindingConstraintMatrices(BaseModel, extra=Extra.forbid, allow_population_by_field_name=True):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def test_manage_binding_constraint(empty_study: FileStudy, command_context: Comm
"name": "BD 2",
"id": "bd 2",
"enabled": False,
"comments": "",
"area1.cluster": 50.0,
"operator": "both",
"type": "daily",
Expand Down Expand Up @@ -127,6 +128,7 @@ def test_manage_binding_constraint(empty_study: FileStudy, command_context: Comm
"id": "bd 1",
"enabled": False,
"area1%area2": "800.0%30",
"comments": "",
"operator": "both",
"type": "weekly",
}
Expand All @@ -151,6 +153,7 @@ def test_manage_binding_constraint(empty_study: FileStudy, command_context: Comm
"id": "bd 2",
"enabled": False,
"area1.cluster": 50.0,
"comments": "",
"operator": "both",
"type": "daily",
}
Expand Down Expand Up @@ -338,7 +341,7 @@ def test_revert(command_context: CommandContext):
operator=BindingConstraintOperator.EQUAL,
coeffs={"a": [0.3]},
values=hourly_matrix_id,
comments=None,
comments="",
command_context=command_context,
)
]
Expand Down

0 comments on commit a6f2020

Please sign in to comment.