Skip to content

Commit 88f81f6

Browse files
authored
Merge pull request #742 from superannotateai/FRIDAY_3530
Fix annotation name validation
2 parents c1b6dd6 + 7496a55 commit 88f81f6

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import List
12
from typing import Optional
23

34
from lib.core.entities.base import BaseItemEntity
@@ -26,7 +27,7 @@ class Config:
2627

2728

2829
class MultiModalItemEntity(BaseItemEntity):
29-
categories: Optional[list[MultiModalItemCategoryEntity]]
30+
categories: Optional[List[MultiModalItemCategoryEntity]]
3031

3132
class Config:
3233
extra = Extra.ignore

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,7 +1861,7 @@ def validate_project_type(self):
18611861

18621862
@staticmethod
18631863
def _validate_json(json_data: dict) -> bool:
1864-
return "metadata" in json_data and "name" in json_data["metadata"]
1864+
return isinstance(json_data.get("metadata", {}).get("name"), str)
18651865

18661866
def list_items(
18671867
self, folder: FolderEntity, item_names: List[str]
@@ -2021,7 +2021,6 @@ def categorization_enabled(self):
20212021

20222022
def execute(self):
20232023
if self.is_valid():
2024-
# TODO check categories status in the project
20252024
categorization_enabled = self.categorization_enabled
20262025
serialized_original_folder_map = {}
20272026
failed, skipped, uploaded = [], [], []
@@ -2033,7 +2032,7 @@ def execute(self):
20332032
folder_name = annotation["metadata"].get("folder_name", "").strip()
20342033
serialized_folder_name = self.serialize_folder_name(folder_name)
20352034
distributed_items[serialized_folder_name][
2036-
annotation["metadata"]["name"]
2035+
str(annotation["metadata"]["name"])
20372036
] = annotation
20382037
valid_items_count += 1
20392038
if serialized_folder_name not in serialized_original_folder_map:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
{"metadata": {"folder_name": "test_folder", "name": "0123456789101112", "item_category": "category1"}, ",data": {"component_id_0": {"value": ["Partially complete, needs review"]}, "component_id_1": {"value": "I am a text input 001"}, "component_id_2": {"value": 11}}}
1+
{"metadata": {"folder_name": "test_folder", "name": "0123456789101112", "item_category": "category1"}, "data": {"component_id_0": {"value": ["Partially complete, needs review"]}, "component_id_1": {"value": "I am a text input 001"}, "component_id_2": {"value": 11}}}
22
{"metadata": {"folder_name": " test_Folder", "name": "item_002", "item_category": "category2"}, "data": {"component_id_0": {"value": ["Partially complete, needs review", "Incomplete"]}, "component_id_1": {"value": "I am a text input 002"}, "component_id_2": {"value": 33}}}
33
{"metadata": {"folder_name": "Test_Folder ", "name": "item_003", "item_category": "category3"}, "data": {"component_id_0": {"value": ["Partially complete, needs review", "Incomplete"]}, "component_id_1": {"value": "I am a text input 003"}, "component_id_2": {"value": 33}}}

tests/integration/annotations/test_upload_annotations.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,19 @@ def test_upload_with_categories(self):
228228
f"{self.PROJECT_NAME}/test_folder", data_spec="multimodal"
229229
)
230230
assert len(annotations) == 3
231+
232+
def test_upload_with_integer_names(self):
233+
data = []
234+
with open(self.JSONL_ANNOTATIONS_WITH_CATEGORIES_PATH) as f:
235+
for i, line in enumerate(f):
236+
_data = json.loads(line)
237+
_data["metadata"]["name"] = i
238+
data.append(_data)
239+
res = sa.upload_annotations(
240+
f"{self.PROJECT_NAME}", annotations=data, data_spec="multimodal"
241+
)
242+
assert len(res["failed"]) == 3
243+
annotations = sa.get_annotations(
244+
f"{self.PROJECT_NAME}/test_folder", data_spec="multimodal"
245+
)
246+
assert len(annotations) == 0

0 commit comments

Comments
 (0)