Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message when submitting a Project with no members #9191

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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"
Expand Down Expand Up @@ -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:
raise SyftException(public_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.types.errors import SyftException


def test_project_creation(worker):
Expand Down Expand Up @@ -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=[]
)

with pytest.raises(SyftException) as exc:
new_project.send()
assert _EMPTY_MEMBER_LIST_ERROR_MESSAGE in exc.value.public_message
Loading