Skip to content

Commit 6e562b1

Browse files
authored
Merge pull request #605 from superannotateai/1935_serializers
changes in entities to backend response independent
2 parents 9a8ff00 + 5d79b22 commit 6e562b1

File tree

13 files changed

+76
-50
lines changed

13 files changed

+76
-50
lines changed

requirements_extra.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Sphinx==6.1.3
1+
Sphinx==6.2.1
22
Jinja2==3.1.2
33
tox==4.4.5
44
sphinx_rtd_theme==1.2.0

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -730,10 +730,7 @@ def search_annotation_classes(
730730
response = self.controller.annotation_classes.list(condition)
731731
if response.errors:
732732
raise AppException(response.errors)
733-
return [
734-
i.dict(exclude={"attribute_groups": {"__all__": {"is_multiselect"}}})
735-
for i in response.data
736-
]
733+
return response.data
737734

738735
def set_project_status(self, project: NotEmptyStr, status: PROJECT_STATUS):
739736
"""Set project status

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from lib.core.entities.project import UserEntity
2020
from lib.core.entities.project import WorkflowEntity
2121
from lib.core.entities.project_entities import BaseEntity
22-
from lib.core.entities.project_entities import ImageInfoEntity
2322
from lib.core.entities.project_entities import S3FileEntity
2423

2524
__all__ = [
@@ -44,7 +43,6 @@
4443
"ConfigEntity",
4544
"WorkflowEntity",
4645
"FolderEntity",
47-
"ImageInfoEntity",
4846
"S3FileEntity",
4947
"AnnotationClassEntity",
5048
"TeamEntity",

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Attribute(TimedBaseModel):
6262
name: Optional[StrictStr]
6363

6464
class Config:
65-
extra = Extra.allow
65+
extra = Extra.ignore
6666

6767
def __hash__(self):
6868
return hash(f"{self.id}{self.group_id}{self.name}")
@@ -73,12 +73,11 @@ class AttributeGroup(TimedBaseModel):
7373
group_type: Optional[GroupTypeEnum]
7474
class_id: Optional[StrictInt]
7575
name: Optional[StrictStr]
76-
is_multiselect: Optional[bool]
7776
attributes: Optional[List[Attribute]]
7877
default_value: Any
7978

8079
class Config:
81-
extra = Extra.allow
80+
extra = Extra.ignore
8281
use_enum_values = True
8382

8483
def __hash__(self):
@@ -97,7 +96,7 @@ def __hash__(self):
9796
return hash(f"{self.id}{self.type}{self.name}")
9897

9998
class Config:
100-
extra = Extra.allow
99+
extra = Extra.ignore
101100
json_encoders = {
102101
HexColor: lambda v: v.__root__,
103102
BaseTitledEnum: lambda v: v.value,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class FolderEntity(TimedBaseModel):
1212
status: Optional[FolderStatus]
1313
project_id: Optional[int]
1414
team_id: Optional[int]
15-
is_root: Optional[bool] = (False,)
15+
is_root: Optional[bool] = False
1616
folder_users: Optional[List[dict]]
1717
completedCount: Optional[int]
1818

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,8 @@ def validate(cls, v: datetime):
3333

3434

3535
class TimedBaseModel(BaseModel):
36-
createdAt: Optional[StringDate] = Field(
37-
None, alias="createdAt", description="Date of creation"
38-
)
39-
updatedAt: Optional[StringDate] = Field(
40-
None, alias="updatedAt", description="Update date"
41-
)
36+
createdAt: Optional[StringDate] = None
37+
updatedAt: Optional[StringDate] = None
4238

4339

4440
class AttachmentEntity(BaseModel):
@@ -59,7 +55,10 @@ class WorkflowEntity(BaseModel):
5955
className: Optional[str]
6056
step: Optional[int]
6157
tool: Optional[int]
62-
attribute: List = (tuple(),)
58+
attribute: List = tuple()
59+
60+
class Config:
61+
extra = Extra.ignore
6362

6463
def __copy__(self):
6564
return WorkflowEntity(step=self.step, tool=self.tool, attribute=self.attribute)
@@ -91,8 +90,8 @@ class Config:
9190
class ProjectEntity(TimedBaseModel):
9291
id: Optional[int]
9392
team_id: Optional[int]
94-
name: Optional[str]
95-
type: Optional[ProjectType]
93+
name: str
94+
type: ProjectType
9695
description: Optional[str]
9796
instructions_link: Optional[str]
9897
creator_id: Optional[str]

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,6 @@ def to_dict(self):
2424
raise NotImplementedError
2525

2626

27-
class ImageInfoEntity(BaseEntity):
28-
def __init__(
29-
self,
30-
uuid=None,
31-
width: float = None,
32-
height: float = None,
33-
):
34-
super().__init__(uuid),
35-
self.width = width
36-
self.height = height
37-
38-
def to_dict(self):
39-
return {
40-
"width": self.width,
41-
"height": self.height,
42-
}
43-
44-
4527
class S3FileEntity(BaseEntity):
4628
def __init__(self, uuid, data, metadata: dict = None):
4729
super().__init__(uuid)

src/superannotate/lib/core/usecases/classes.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ def __init__(
2828
def execute(self):
2929
response = self._service_provider.annotation_classes.list(self._condition)
3030
if response.ok:
31-
self._response.data = response.data
31+
classes = [
32+
entity.dict(by_alias=True, exclude_unset=True)
33+
for entity in response.data
34+
]
35+
self._response.data = classes
3236
else:
3337
self._response.errors = response.error
3438
return self._response

tests/__init__.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
DATA_SET_PATH = Path(__file__).parent / "data_set"
99
sys.path.insert(0, str(LIB_PATH))
1010

11-
__all__ = ["DATA_SET_PATH"]
1211

13-
# from src.superannotate.lib.core import setup_logging
14-
#
15-
# logger = get_default_logger()
16-
# logger.setLevel("DEBUG")
12+
def compare_result(result: dict, expected: dict, ignore_keys: set = None):
13+
for key in result:
14+
if ignore_keys and key in ignore_keys:
15+
continue
16+
assert result[key] == expected[key]
17+
return True
18+
19+
20+
__all__ = ["DATA_SET_PATH", "compare_result"]

tests/integration/classes/test_create_annotation_class.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_multi_select_to_checklist(self):
6464
attribute_groups=[
6565
{
6666
"name": "test",
67-
"is_multiselect": 1,
67+
"group_type": "checklist",
6868
"attributes": [{"name": "Car"}, {"name": "Track"}, {"name": "Bus"}],
6969
}
7070
],

0 commit comments

Comments
 (0)