diff --git a/src/antares/model/study.py b/src/antares/model/study.py index 3b429e8..b0a1303 100644 --- a/src/antares/model/study.py +++ b/src/antares/model/study.py @@ -265,6 +265,9 @@ def create_link( properties: Optional[LinkProperties] = None, ui: Optional[LinkUi] = None, ) -> Link: + if area_from == area_to: + raise LinkCreationError(area_from, area_to, "A link cannot start and end at the same area") + sorted_areas = sorted([area_from, area_to]) area_from, area_to = sorted_areas diff --git a/tests/antares/services/api_services/test_study_api.py b/tests/antares/services/api_services/test_study_api.py index 695e416..fbbb8fa 100644 --- a/tests/antares/services/api_services/test_study_api.py +++ b/tests/antares/services/api_services/test_study_api.py @@ -313,3 +313,20 @@ def test_create_link_unknown_area(self): match=f"Could not create the link {area_from} / {area_to}: {area_to} does not exist", ): self.study.create_link(area_from=area_from, area_to=area_to) + + def test_create_link_same_area(self): + area = "area_1" + + self.study._areas[area] = Area( + area, + self.study._area_service, + Mock(), + Mock(), + Mock(), + ) + + with pytest.raises( + LinkCreationError, + match=f"Could not create the link {area} / {area}: A link cannot start and end at the same area", + ): + self.study.create_link(area_from=area, area_to=area)