Skip to content

Commit

Permalink
remove last usage of json module
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Sep 20, 2024
1 parent c3b048f commit beee396
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/antares/service/api_services/link_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from antares.model.area import Area
from antares.model.link import LinkProperties, LinkUi, Link
from antares.service.base_services import BaseLinkService
from antares.tools.ini_tool import check_if_none


class LinkApiService(BaseLinkService):
Expand Down Expand Up @@ -73,10 +72,10 @@ def create_link(
json_file = response.json()
# TODO update to use check_if_none or similar
if properties or ui:
link_properties = json.loads(
check_if_none(properties, LinkProperties()).model_dump_json(by_alias=True, exclude_none=True)
link_properties = (properties or LinkProperties()).model_dump(
mode="json", by_alias=True, exclude_none=True
)
link_ui = json.loads(check_if_none(ui, LinkUi()).model_dump_json(by_alias=True, exclude_none=True))
link_ui = (ui or LinkUi()).model_dump(mode="json", by_alias=True, exclude_none=True)
body = {**link_properties, **link_ui}
if body:
json_file = _join_filter_values_for_json(json_file, body)
Expand All @@ -92,13 +91,13 @@ def create_link(
else:
json_properties[key] = value
del json_file[key]
link_ui = LinkUi.model_validate(json_file)
link_properties = LinkProperties.model_validate(json_properties)
ui = LinkUi.model_validate(json_file)
created_properties = LinkProperties.model_validate(json_properties)

except APIError as e:
raise LinkCreationError(area_from.id, area_to.id, e.message) from e

return Link(area_from, area_to, self, link_properties, link_ui)
return Link(area_from, area_to, self, created_properties, ui)

def delete_link(self, link: Link) -> None:
area_from_id = link.area_from.id
Expand Down

0 comments on commit beee396

Please sign in to comment.