Skip to content

Commit 5b3ab3e

Browse files
committed
Fixed query fields
1 parent dacf034 commit 5b3ab3e

File tree

5 files changed

+21
-28
lines changed

5 files changed

+21
-28
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,12 @@ def add_path(self, project_name: str, folder_name: str):
279279
return self
280280

281281
@staticmethod
282-
def map_fields(entity: dict, drop_path: bool = True) -> dict:
282+
def map_fields(entity: dict) -> dict:
283283
if "metadata" in entity:
284284
entity["url"] = entity["metadata"]["path"]
285285
else:
286286
entity["url"] = entity["path"]
287-
if drop_path:
288-
entity["path"] = None
287+
entity["path"] = None
289288
return entity
290289

291290

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from concurrent.futures import ThreadPoolExecutor
66
from typing import Dict
77
from typing import List
8+
from typing import Union
89

910
import lib.core as constants
1011
from lib.core.conditions import Condition
@@ -37,11 +38,13 @@
3738

3839

3940
def serialize_item_entity(
40-
entity: BaseItemEntity, project: ProjectEntity, drop_path: bool = True
41+
entity: Union[BaseItemEntity, dict], project: ProjectEntity, map_fields: bool = True
4142
) -> BaseItemEntity:
42-
entity = BaseItemEntity(
43-
**BaseItemEntity.map_fields(entity.dict(), drop_path=drop_path)
44-
)
43+
if isinstance(entity, BaseItemEntity):
44+
entity = entity.dict()
45+
if map_fields:
46+
entity = BaseItemEntity.map_fields(entity)
47+
entity = BaseItemEntity(**entity)
4548
if project.upload_state != constants.UploadState.EXTERNAL.value:
4649
entity.url = None
4750
if project.type in constants.ProjectType.images:
@@ -142,14 +145,14 @@ def execute(self) -> Response:
142145
data = []
143146
for i, item in enumerate(service_response.data):
144147
# tmp wrapper
145-
if hasattr(item, "assignment"):
146-
item.assignments = item.assignment
147-
tmp_item = serialize_item_entity(
148-
BaseItemEntity(**item), self._project
148+
if "assignment" in item:
149+
item["assignments"] = item.pop("assignment")
150+
item["url"] = item["path"]
151+
item["path"] = (
152+
f"{self._project.name}"
153+
f"{'/' + item['folder_name'] if not item['is_root_folder'] else ''}"
149154
)
150-
folder_path = f"{'/' + item['folder_name'] if not item['is_root_folder'] else ''}"
151-
tmp_item.path = f"{self._project.name}" + folder_path
152-
data.append(tmp_item)
155+
data.append(item)
153156
self._response.data = data
154157
else:
155158
self._response.errors = service_response.data

src/superannotate/lib/infrastructure/controller.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,16 +452,16 @@ def process_response(
452452
items: List[BaseItemEntity],
453453
project: ProjectEntity,
454454
folder: FolderEntity,
455-
replace_path: bool = True,
455+
map_fields: bool = True,
456456
) -> List[BaseItemEntity]:
457457
"""Process the response data and return a list of serialized items."""
458458
data = []
459459
for item in items:
460-
if replace_path:
460+
if map_fields:
461461
item = usecases.serialize_item_entity(item, project)
462462
item = usecases.add_item_path(project, folder, item)
463463
else:
464-
item = usecases.serialize_item_entity(item, project, drop_path=False)
464+
item = usecases.serialize_item_entity(item, project, map_fields=False)
465465
item.annotation_status = service_provider.get_annotation_status_name(
466466
project, item.annotation_status
467467
)
@@ -1359,5 +1359,5 @@ def query_entities(
13591359
raise AppException(response.errors)
13601360
items = response.data
13611361
return ItemManager.process_response(
1362-
self.service_provider, items, project, folder, replace_path=False
1362+
self.service_provider, items, project, folder, map_fields=False
13631363
)

src/superannotate/lib/infrastructure/services/item_service.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,4 @@ def list(self, project_id: int, folder_id: Optional[int], query: Query):
4343
).decode()
4444
},
4545
)
46-
# headers={
47-
# "x-sa-entity-context": base64.b64encode(
48-
# f'{{"team_id":{self.client.team_id},' +
49-
# f'"project_id":{project_id},"folder_id":{folder_id}}}'.encode(
50-
# "utf-8"
51-
# )
52-
# ).decode()
53-
# },
54-
# )
5546
return result

tests/integration/items/test_saqul_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,4 @@ def test_query(self):
8585
try:
8686
sa.query(self.PROJECT_NAME, self.TEST_QUERY)
8787
except Exception as e:
88-
self.assertEqual(str(e), "Incorrect query.")
88+
self.assertEqual(str(e), "Unsupported project type.")

0 commit comments

Comments
 (0)