Skip to content

Commit 1311d87

Browse files
authored
Merge pull request #492 from superannotateai/1278_serializers_fix
1278 serializers fix
2 parents 69c52fd + 3b8d306 commit 1311d87

25 files changed

+708
-409
lines changed

src/superannotate/lib/app/interface/cli_interface.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,7 @@ def _upload_annotations(
195195
output_dir=temp_dir,
196196
dataset_format=format,
197197
dataset_name=dataset_name,
198-
project_type=constances.ProjectType.get_name(
199-
project["project"].type
200-
),
198+
project_type=project.type.name,
201199
task=task,
202200
)
203201
annotations_path = temp_dir

src/superannotate/lib/app/interface/sdk_interface.py

Lines changed: 38 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,7 @@ def search_projects(
162162
if return_metadata:
163163
return [
164164
ProjectSerializer(project).serialize(
165-
exclude={
166-
"annotation_classes",
167-
"workflows",
168-
"settings",
169-
"contributors",
170-
"classes",
171-
}
165+
exclude={"settings", "workflows", "contributors", "classes"}
172166
)
173167
for project in result
174168
]
@@ -434,16 +428,14 @@ def copy_image(
434428
destination_project
435429
).data
436430

437-
if destination_project_metadata["project"].type in [
431+
if destination_project_metadata.type.value in [
438432
constants.ProjectType.VIDEO.value,
439433
constants.ProjectType.DOCUMENT.value,
440-
] or source_project_metadata["project"].type in [
434+
] or source_project_metadata.type.value in [
441435
constants.ProjectType.VIDEO.value,
442436
constants.ProjectType.DOCUMENT.value,
443437
]:
444-
raise AppException(
445-
LIMITED_FUNCTIONS[source_project_metadata["project"].type]
446-
)
438+
raise AppException(LIMITED_FUNCTIONS[source_project_metadata.type])
447439

448440
response = self.controller.copy_image(
449441
from_project_name=source_project_name,
@@ -517,17 +509,11 @@ def get_project_metadata(
517509
include_workflow,
518510
include_contributors,
519511
include_complete_image_count,
520-
).data
521-
522-
metadata = ProjectSerializer(response["project"]).serialize()
512+
)
513+
if response.errors:
514+
raise AppException(response.errors)
523515

524-
for elem in "classes", "workflows", "contributors":
525-
if response.get(elem):
526-
metadata[elem] = [
527-
BaseSerializer(attribute).serialize()
528-
for attribute in response[elem]
529-
]
530-
return metadata
516+
return ProjectSerializer(response.data).serialize()
531517

532518
def get_project_settings(self, project: Union[NotEmptyStr, dict]):
533519
"""Gets project's settings.
@@ -543,7 +529,8 @@ def get_project_settings(self, project: Union[NotEmptyStr, dict]):
543529
project_name, folder_name = extract_project_folder(project)
544530
settings = self.controller.get_project_settings(project_name=project_name)
545531
settings = [
546-
SettingsSerializer(attribute).serialize() for attribute in settings.data
532+
SettingsSerializer(attribute.dict()).serialize()
533+
for attribute in settings.data
547534
]
548535
return settings
549536

@@ -584,7 +571,10 @@ def search_annotation_classes(
584571
)
585572
if response.errors:
586573
raise AppException(response.errors)
587-
return [BaseSerializer(i).serialize(exclude_unset=True) for i in response.data]
574+
return [
575+
i.dict(exclude={"attribute_groups": {"__all__": {"is_multiselect"}}})
576+
for i in response.data
577+
]
588578

589579
def set_project_default_image_quality_in_editor(
590580
self,
@@ -1516,11 +1506,11 @@ def upload_preannotations_from_folder_to_project(
15161506
project_name, folder_name = extract_project_folder(project)
15171507
project_folder_name = project_name + (f"/{folder_name}" if folder_name else "")
15181508
project = self.controller.get_project_metadata(project_name).data
1519-
if project["project"].type in [
1520-
constants.ProjectType.VIDEO.value,
1521-
constants.ProjectType.DOCUMENT.value,
1509+
if project.type in [
1510+
constants.ProjectType.VIDEO,
1511+
constants.ProjectType.DOCUMENT,
15221512
]:
1523-
raise AppException(LIMITED_FUNCTIONS[project["project"].type])
1513+
raise AppException(LIMITED_FUNCTIONS[project.type])
15241514
if recursive_subfolders:
15251515
logger.info(
15261516
"When using recursive subfolder parsing same name annotations in different "
@@ -1579,11 +1569,11 @@ def upload_image_annotations(
15791569
project_name, folder_name = extract_project_folder(project)
15801570

15811571
project = self.controller.get_project_metadata(project_name).data
1582-
if project["project"].type in [
1583-
constants.ProjectType.VIDEO.value,
1584-
constants.ProjectType.DOCUMENT.value,
1572+
if project.type in [
1573+
constants.ProjectType.VIDEO,
1574+
constants.ProjectType.DOCUMENT,
15851575
]:
1586-
raise AppException(LIMITED_FUNCTIONS[project["project"].type])
1576+
raise AppException(LIMITED_FUNCTIONS[project.type])
15871577

15881578
if not mask:
15891579
if not isinstance(annotation_json, dict):
@@ -1665,11 +1655,11 @@ def benchmark(
16651655
project_name = project["name"]
16661656

16671657
project = self.controller.get_project_metadata(project_name).data
1668-
if project["project"].type in [
1669-
constants.ProjectType.VIDEO.value,
1670-
constants.ProjectType.DOCUMENT.value,
1658+
if project.type in [
1659+
constants.ProjectType.VIDEO,
1660+
constants.ProjectType.DOCUMENT,
16711661
]:
1672-
raise AppException(LIMITED_FUNCTIONS[project["project"].type])
1662+
raise AppException(LIMITED_FUNCTIONS[project.type])
16731663

16741664
if not export_root:
16751665
with tempfile.TemporaryDirectory() as temp_dir:
@@ -1817,11 +1807,11 @@ def add_annotation_bbox_to_image(
18171807
"""
18181808
project_name, folder_name = extract_project_folder(project)
18191809
project = self.controller.get_project_metadata(project_name).data
1820-
if project["project"].type in [
1821-
constants.ProjectType.VIDEO.value,
1822-
constants.ProjectType.DOCUMENT.value,
1810+
if project.type in [
1811+
constants.ProjectType.VIDEO,
1812+
constants.ProjectType.DOCUMENT,
18231813
]:
1824-
raise AppException(LIMITED_FUNCTIONS[project["project"].type])
1814+
raise AppException(LIMITED_FUNCTIONS[project.type])
18251815
response = self.controller.get_annotations(
18261816
project_name=project_name,
18271817
folder_name=folder_name,
@@ -1875,11 +1865,11 @@ def add_annotation_point_to_image(
18751865
"""
18761866
project_name, folder_name = extract_project_folder(project)
18771867
project = self.controller.get_project_metadata(project_name).data
1878-
if project["project"].type in [
1879-
constants.ProjectType.VIDEO.value,
1880-
constants.ProjectType.DOCUMENT.value,
1868+
if project.type in [
1869+
constants.ProjectType.VIDEO,
1870+
constants.ProjectType.DOCUMENT,
18811871
]:
1882-
raise AppException(LIMITED_FUNCTIONS[project["project"].type])
1872+
raise AppException(LIMITED_FUNCTIONS[project.type])
18831873
response = self.controller.get_annotations(
18841874
project_name=project_name,
18851875
folder_name=folder_name,
@@ -1931,11 +1921,11 @@ def add_annotation_comment_to_image(
19311921
"""
19321922
project_name, folder_name = extract_project_folder(project)
19331923
project = self.controller.get_project_metadata(project_name).data
1934-
if project["project"].type in [
1935-
constants.ProjectType.VIDEO.value,
1936-
constants.ProjectType.DOCUMENT.value,
1924+
if project.type in [
1925+
constants.ProjectType.VIDEO,
1926+
constants.ProjectType.DOCUMENT,
19371927
]:
1938-
raise AppException(LIMITED_FUNCTIONS[project["project"].type])
1928+
raise AppException(LIMITED_FUNCTIONS[project.type])
19391929
response = self.controller.get_annotations(
19401930
project_name=project_name,
19411931
folder_name=folder_name,

src/superannotate/lib/app/serializers.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class ProjectSerializer(BaseSerializer):
118118
def serialize(
119119
self,
120120
fields: List[str] = None,
121-
by_alias: bool = False,
121+
by_alias: bool = True,
122122
flat: bool = False,
123123
exclude: Set[str] = None,
124124
):
@@ -130,11 +130,9 @@ def serialize(
130130
data["settings"] = [
131131
SettingsSerializer(setting).serialize() for setting in data["settings"]
132132
]
133-
data["type"] = constance.ProjectType.get_name(data["type"])
134-
if data.get("status"):
135-
data["status"] = constance.ProjectStatus.get_name(data["status"])
136-
else:
133+
if not data.get("status"):
137134
data["status"] = "Undefined"
135+
138136
if data.get("upload_state"):
139137
data["upload_state"] = constance.UploadState(data["upload_state"]).name
140138
if data.get("users"):
@@ -152,18 +150,14 @@ def serialize(self):
152150
return data
153151

154152

155-
class SettingsSerializer(BaseSerializer):
156-
def serialize(
157-
self,
158-
fields: List[str] = None,
159-
by_alias: bool = True,
160-
flat: bool = False,
161-
exclude=None,
162-
):
163-
data = super().serialize(fields, by_alias, flat, exclude)
164-
if data["attribute"] == "ImageQuality":
165-
data["value"] = constance.ImageQuality.get_name(data["value"])
166-
return data
153+
class SettingsSerializer:
154+
def __init__(self, data: dict):
155+
self.data = data
156+
157+
def serialize(self):
158+
if self.data["attribute"] == "ImageQuality":
159+
self.data["value"] = constance.ImageQuality.get_name(self.data["value"])
160+
return self.data
167161

168162

169163
class EntitySerializer:

src/superannotate/lib/core/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@
7979
)
8080

8181
LIMITED_FUNCTIONS = {
82-
ProjectType.VIDEO.value: DEPRECATED_VIDEO_PROJECTS_MESSAGE,
83-
ProjectType.DOCUMENT.value: DEPRECATED_DOCUMENT_PROJECTS_MESSAGE,
82+
ProjectType.VIDEO: DEPRECATED_VIDEO_PROJECTS_MESSAGE,
83+
ProjectType.DOCUMENT: DEPRECATED_DOCUMENT_PROJECTS_MESSAGE,
8484
}
8585

8686
METADATA_DEPRICATED_FOR_PIXEL = (

src/superannotate/lib/core/entities/__init__.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from lib.core.entities.base import AttachmentEntity
21
from lib.core.entities.base import BaseItemEntity
3-
from lib.core.entities.base import ProjectEntity
4-
from lib.core.entities.base import SettingEntity
52
from lib.core.entities.base import SubSetEntity
63
from lib.core.entities.classes import AnnotationClassEntity
74
from lib.core.entities.integrations import IntegrationEntity
85
from lib.core.entities.items import DocumentEntity
96
from lib.core.entities.items import TmpImageEntity
107
from lib.core.entities.items import VideoEntity
8+
from lib.core.entities.project import AttachmentEntity
9+
from lib.core.entities.project import ProjectEntity
10+
from lib.core.entities.project import SettingEntity
1111
from lib.core.entities.project_entities import BaseEntity
1212
from lib.core.entities.project_entities import ConfigEntity
1313
from lib.core.entities.project_entities import FolderEntity
@@ -20,8 +20,6 @@
2020
from lib.core.entities.project_entities import WorkflowEntity
2121

2222

23-
# from lib.core.entities.project_entities import ProjectEntity
24-
2523
__all__ = [
2624
# base
2725
"SettingEntity",
@@ -47,10 +45,4 @@
4745
"TeamEntity",
4846
"MLModelEntity",
4947
"IntegrationEntity",
50-
# annotations
51-
"DocumentAnnotation",
52-
"VideoAnnotation",
53-
"VectorAnnotation",
54-
"PixelAnnotation",
55-
"VideoExportAnnotation",
5648
]

0 commit comments

Comments
 (0)