Skip to content

Commit

Permalink
Improve error message when submitting a Project with no members
Browse files Browse the repository at this point in the history
  • Loading branch information
kiendang committed Aug 22, 2024
1 parent 3422f9a commit 7a2fdc0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/syft/src/syft/service/project/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,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"
Expand Down Expand Up @@ -1258,6 +1261,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]
Expand Down
12 changes: 12 additions & 0 deletions packages/syft/tests/syft/project/project_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -108,3 +110,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

0 comments on commit 7a2fdc0

Please sign in to comment.