Skip to content

Commit 58e6e7a

Browse files
committed
fix get_anntations
1 parent 2119d6c commit 58e6e7a

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/superannotate/lib/infrastructure/services.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,17 +1636,26 @@ def get_schema(
16361636
def sort_items_by_size(
16371637
self, item_names: List[str], team_id: int, project_id: int, folder_id: int
16381638
):
1639-
1639+
chunk_size = 2000
16401640
query_params = {
16411641
"team_id": team_id,
16421642
"project_id": project_id,
16431643
"folder_id": folder_id,
16441644
}
16451645

1646+
response_data = {"small": [], "large": []}
16461647
url = urljoin(self.assets_provider_url, self.URL_CLASSIFY_ITEM_SIZE)
1647-
1648-
body = {"item_names": item_names, "folder_id": folder_id}
1649-
response = self._request(url=url, method="POST", params=query_params, data=body)
1650-
if not response.ok:
1651-
raise AppException(response.json().get("errors", "Undefined"))
1652-
return response.json()
1648+
for i in range(0, len(item_names), chunk_size):
1649+
body = {
1650+
"item_names": item_names[i : i + chunk_size],
1651+
"folder_id": folder_id,
1652+
} # noqa
1653+
response = self._request(
1654+
url=url, method="POST", params=query_params, data=body
1655+
)
1656+
if not response.ok:
1657+
raise AppException(response.json().get("errors", "Undefined"))
1658+
response_json = response.json()
1659+
response_data["small"].extend(response_json.get("small", []))
1660+
response_data["large"].extend(response_json.get("large", []))
1661+
return response_data

tests/integration/annotations/test_get_annotations.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ def test_get_annotations_all_plus_folder(self):
110110
annotations = sa.get_annotations(f"{self.PROJECT_NAME}")
111111
self.assertEqual(len(annotations), 4)
112112

113+
def test_get_annotations10000(self):
114+
count = 10000
115+
sa.attach_items(
116+
self.PROJECT_NAME,
117+
[{"name": f"example_image_{i}.jpg", "url": f"url_{i}"} for i in range(1, count)] # noqa
118+
)
119+
a = sa.get_annotations(self.PROJECT_NAME)
120+
assert len(a) == count
121+
122+
113123

114124
class TestGetAnnotationsVideo(BaseTestCase):
115125
PROJECT_NAME = "test attach multiple video urls"
@@ -160,3 +170,4 @@ def test_video_annotation_upload_folder(self):
160170
sa.upload_annotations_from_folder_to_project(path, self.annotations_path)
161171
annotations = sa.get_annotations(path)
162172
self.assertEqual(len(annotations), 2)
173+

0 commit comments

Comments
 (0)