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

Remove disallowed fields from project before POSTing #79

Merged
merged 2 commits into from
Nov 3, 2022
Merged
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
11 changes: 11 additions & 0 deletions geti_sdk/data_models/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Label:
"""

_identifier_fields: ClassVar[List[str]] = ["id", "hotkey"]
_GET_only_fields: ClassVar[List[str]] = ["is_empty", "is_anomalous"]

name: str
color: str
Expand All @@ -80,6 +81,16 @@ def to_ote(self, task_type: TaskType) -> LabelEntity:
color=Color.from_hex_str(self.color),
)

def prepare_for_post(self) -> None:
"""
Set all fields to None that are not valid for making a POST request to the
/projects endpoint.

:return:
"""
for field_name in self._GET_only_fields:
setattr(self, field_name, None)


@attr.define
class ScoredLabel:
Expand Down
35 changes: 35 additions & 0 deletions geti_sdk/data_models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ def deidentify(self) -> None:
for task in self.tasks:
task.deidentify()

def prepare_for_post(self) -> None:
"""
Set all fields to None that are not valid for making a POST request to the
/projects endpoint.

:return:
"""
for task in self.tasks:
task.prepare_for_post()


@attr.define
class Dataset:
Expand All @@ -151,6 +161,7 @@ class Dataset:
"""

_identifier_fields: ClassVar[str] = ["id", "creation_time"]
_GET_only_fields: ClassVar[List[str]] = ["use_for_training", "creation_time"]

name: str
id: Optional[str] = None
Expand All @@ -163,6 +174,16 @@ def deidentify(self) -> None:
"""
deidentify(self)

def prepare_for_post(self) -> None:
"""
Set all fields to None that are not valid for making a POST request to the
/projects endpoint.

:return:
"""
for field_name in self._GET_only_fields:
setattr(self, field_name, None)


@attr.define
class Project:
Expand All @@ -184,6 +205,7 @@ class Project:
"creation_time",
"creator_id",
]
_GET_only_fields: ClassVar[List[str]] = ["thumbnail", "score", "performance"]

name: str
pipeline: Pipeline
Expand Down Expand Up @@ -235,6 +257,19 @@ def deidentify(self) -> None:
for dataset in self.datasets:
dataset.deidentify()

def prepare_for_post(self) -> None:
"""
Set all fields to None that are not valid for making a POST request to the
/projects endpoint.

:return:
"""
for field_name in self._GET_only_fields:
setattr(self, field_name, None)
self.pipeline.prepare_for_post()
for dataset in self.datasets:
dataset.prepare_for_post()

def to_dict(self) -> Dict[str, Any]:
"""
Convert the project to a dictionary representation.
Expand Down
18 changes: 18 additions & 0 deletions geti_sdk/data_models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,21 @@ def summary(self) -> str:
f"Parent: {label.parent_id}\n"
)
return summary_str

def prepare_for_post(self) -> None:
"""
Set all fields to None that are not valid for making a POST request to the
/projects endpoint.

:return:
"""
if self.labels is not None:
labels_indices_to_pop: List[int] = []
for ii, label in enumerate(self.labels):
if label.is_empty:
labels_indices_to_pop.append(ii)
label.prepare_for_post()
for index in labels_indices_to_pop:
# Empty labels are not allowed to be specified explicitly in a POST
# request
self.labels.pop(index)
1 change: 1 addition & 0 deletions geti_sdk/rest_clients/project_client/project_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ def create_project_from_folder(
f"Creating project '{project.name}' from parameters in "
f"configuration file at {path_to_project}."
)
project.prepare_for_post()
return self.get_or_create_project(**project.get_parameters())

@staticmethod
Expand Down
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/fixtures/cassettes/TestGeti.test_deployment.cassette
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/fixtures/cassettes/TestGetiSession.test_logout.cassette
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/fixtures/cassettes/geti.cassette
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/fixtures/cassettes/geti_sdk_test_geti.cassette
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/fixtures/cassettes/geti_sdk_test_geti_deletion.cassette
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/fixtures/cassettes/geti_sdk_test_image_client.cassette
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Loading