diff --git a/packages/syft/src/syft/service/project/project.py b/packages/syft/src/syft/service/project/project.py index 0b64a9d8870..406a2d7508e 100644 --- a/packages/syft/src/syft/service/project/project.py +++ b/packages/syft/src/syft/service/project/project.py @@ -1106,6 +1106,9 @@ def pending_requests(self) -> int: ) +_EMPTY_MEMBER_LIST_ERROR_MESSAGE = "Project needs at least 1 member." + + @serializable(without=["bootstrap_events", "clients"]) class ProjectSubmit(SyftObject): __canonical_name__ = "ProjectSubmit" @@ -1232,6 +1235,9 @@ def start(self, return_all_projects: bool = False) -> Project | list[Project]: return self.send(return_all_projects=return_all_projects) def send(self, return_all_projects: bool = False) -> Project | list[Project]: + if len(self.clients) == 0: + return SyftError(message=_EMPTY_MEMBER_LIST_ERROR_MESSAGE) + # Currently we are assuming that the first member is the leader # This would be changed in our future leaderless approach leader = self.clients[0] diff --git a/packages/syft/tests/syft/project/project_test.py b/packages/syft/tests/syft/project/project_test.py index ba531ff2aac..abb18921a19 100644 --- a/packages/syft/tests/syft/project/project_test.py +++ b/packages/syft/tests/syft/project/project_test.py @@ -5,6 +5,8 @@ # syft absolute import syft as sy from syft.service.project.project import Project +from syft.service.project.project import _EMPTY_MEMBER_LIST_ERROR_MESSAGE +from syft.service.response import SyftError def test_project_creation(worker): @@ -110,3 +112,13 @@ def test_project_serde(worker): deser_data = sy.deserialize(ser_data, from_bytes=True) assert isinstance(deser_data, type(project)) assert deser_data == project + + +def test_submit_project_with_empty_member_list_error() -> None: + new_project = sy.Project( + name="My Cool Project", description="My Cool Description", members=[] + ) + + res = new_project.send() + assert isinstance(res, SyftError) + assert _EMPTY_MEMBER_LIST_ERROR_MESSAGE in res.message