Skip to content

Commit 030f8c1

Browse files
Vaghinak BasentsyanVaghinak Basentsyan
authored andcommitted
Fixed recurive upload issue
1 parent 60d2ff3 commit 030f8c1

File tree

17 files changed

+8918
-43
lines changed

17 files changed

+8918
-43
lines changed

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
minversion = 3.0
33
log_cli=true
44
python_files = test_*.py
5-
addopts = -n32 --dist=loadscope
5+
;addopts = -n32 --dist=loadscope

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ def search_projects(
149149
:type name: str
150150
:param return_metadata: return metadata of projects instead of names
151151
:type return_metadata: bool
152-
:param include_complete_image_count: include complete image count in response
152+
:param include_complete_image_count: return projects that have completed images and
153+
include the number of completed images in response.
153154
:type include_complete_image_count: bool
154155
155156
:return: project names or metadatas
@@ -1075,7 +1076,9 @@ def get_image_metadata(project: Union[str, dict], image_name: str, *_, **__):
10751076
@Trackable
10761077
@typechecked
10771078
def set_images_annotation_statuses(
1078-
project: Union[str, dict], image_names: Optional[List[str]], annotation_status: str,
1079+
project: Union[str, dict],
1080+
annotation_status: str,
1081+
image_names: Optional[List[str]] = None,
10791082
):
10801083
"""Sets annotation statuses of images
10811084
@@ -1092,7 +1095,7 @@ def set_images_annotation_statuses(
10921095
project_name, folder_name, image_names, annotation_status
10931096
)
10941097
if response.errors:
1095-
raise AppException(response.errors)
1098+
raise AppException("Failed to change status.")
10961099
logger.info("Annotations status of images changed")
10971100

10981101

@@ -1109,7 +1112,7 @@ def delete_images(project: Union[str, dict], image_names: Optional[List[str]] =
11091112
project_name, folder_name = extract_project_folder(project)
11101113

11111114
if not isinstance(image_names, list) and image_names is not None:
1112-
raise AppException("Image_names should be a list of strs or None.")
1115+
raise AppException("Image_names should be a list of str or None.")
11131116

11141117
response = controller.delete_images(
11151118
project_name=project_name, folder_name=folder_name, image_names=image_names
@@ -1118,7 +1121,7 @@ def delete_images(project: Union[str, dict], image_names: Optional[List[str]] =
11181121
raise AppException(response.errors)
11191122

11201123
logger.info(
1121-
f"Images deleted in project {project_name}{'' if folder_name else '/' + folder_name}"
1124+
f"Images deleted in project {project_name}{'/' + folder_name if folder_name else ''}"
11221125
)
11231126

11241127

src/superannotate/lib/core/entities.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ def __init__(
238238
segmentation_status: int = SegmentationStatus.NOT_STARTED.value,
239239
prediction_status: int = SegmentationStatus.NOT_STARTED.value,
240240
meta: ImageInfoEntity = ImageInfoEntity(),
241+
**_
241242
):
242243
super().__init__(uuid)
243244
self.team_id = team_id
@@ -258,6 +259,16 @@ def __init__(
258259
self.prediction_status = prediction_status
259260
self.meta = meta
260261

262+
@staticmethod
263+
def from_dict(**kwargs):
264+
if "id" in kwargs:
265+
kwargs["uuid"] = kwargs["id"]
266+
del kwargs["id"]
267+
if "annotation_status" in kwargs:
268+
kwargs["annotation_status_code"] = kwargs["annotation_status"]
269+
del kwargs["annotation_status"]
270+
return ImageEntity(**kwargs)
271+
261272
def to_dict(self):
262273
return {
263274
"id": self.uuid,

src/superannotate/lib/core/usecases.py

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -515,21 +515,27 @@ def __init__(
515515
folder: FolderEntity,
516516
image_name: str,
517517
images: BaseReadOnlyRepository,
518+
service: SuerannotateServiceProvider,
518519
):
519520
super().__init__()
520521
self._project = project
521522
self._folder = folder
522523
self._images = images
523524
self._image_name = image_name
525+
self._service = service
524526

525527
def execute(self):
526-
condition = (
527-
Condition("team_id", self._project.team_id, EQ)
528-
& Condition("project_id", self._project.uuid, EQ)
529-
& Condition("folder_id", self._folder.uuid, EQ)
530-
& Condition("name", self._image_name, EQ)
528+
images = (
529+
GetBulkImages(
530+
service=self._service,
531+
project_id=self._project.uuid,
532+
team_id=self._project.team_id,
533+
folder_id=self._folder.uuid,
534+
images=[self._image_name],
535+
)
536+
.execute()
537+
.data
531538
)
532-
images = self._images.get_all(condition)
533539
if images:
534540
self._response.data = images[0]
535541
else:
@@ -731,7 +737,7 @@ def execute(self):
731737
"height": image.meta.height,
732738
}
733739

734-
uploaded = self._backend_service.attach_files(
740+
backend_response = self._backend_service.attach_files(
735741
project_id=self._project.uuid,
736742
folder_id=self._folder.uuid,
737743
team_id=self._project.team_id,
@@ -740,8 +746,10 @@ def execute(self):
740746
upload_state_code=self.upload_state_code,
741747
meta=meta,
742748
)
743-
744-
self._response.data = uploaded, duplications
749+
if isinstance(backend_response, dict) and "error" in backend_response:
750+
self._response.errors = AppException(backend_response["error"])
751+
else:
752+
self._response.data = backend_response, duplications
745753
return self._response
746754

747755

@@ -1634,13 +1642,17 @@ def execute(self):
16341642
image.name for image in self._images_repo.get_all(condition)
16351643
]
16361644
for i in range(0, len(self._image_names), self.CHUNK_SIZE):
1637-
self._response.data = self._service.set_images_statuses_bulk(
1638-
image_names=self._image_names,
1645+
status_changed = self._service.set_images_statuses_bulk(
1646+
image_names=self._image_names[
1647+
i : i + self.CHUNK_SIZE
1648+
], # noqa: E203
16391649
team_id=self._team_id,
16401650
project_id=self._project_id,
16411651
folder_id=self._folder_id,
16421652
annotation_status=self._annotation_status,
16431653
)
1654+
if not status_changed:
1655+
self._response.errors = AppException("Failed to change status.")
16441656
return self._response
16451657

16461658

@@ -1994,6 +2006,7 @@ def image_use_case(self):
19942006
folder=self._folder,
19952007
image_name=self._image_name,
19962008
images=self._images,
2009+
service=self._service,
19972010
)
19982011
return use_case
19992012

@@ -2092,6 +2105,7 @@ def image_use_case(self):
20922105
folder=self._folder,
20932106
image_name=self._image_name,
20942107
images=self._images,
2108+
service=self._service,
20952109
)
20962110

20972111
def validate_project_type(self):
@@ -2162,6 +2176,7 @@ def __init__(
21622176
@property
21632177
def image_use_case(self):
21642178
return GetImageUseCase(
2179+
service=self._service,
21652180
project=self._project,
21662181
folder=self._folder,
21672182
image_name=self._image_name,
@@ -2254,6 +2269,7 @@ def image_use_case(self):
22542269
folder=self._folder,
22552270
image_name=self._image_name,
22562271
images=self._images,
2272+
service=self._service,
22572273
)
22582274

22592275
def execute(self):
@@ -4406,9 +4422,18 @@ def images_to_upload(self):
44064422
x not in Path(path).name for x in self.exclude_file_patterns
44074423
]
44084424
non_in_service_list = [x not in Path(path).name for x in image_names]
4409-
if all(not_in_exclude_list) and all(non_in_service_list):
4425+
if (
4426+
all(not_in_exclude_list)
4427+
and all(non_in_service_list)
4428+
and not any(
4429+
Path(path).name in filtered_path
4430+
for filtered_path in filtered_paths
4431+
)
4432+
):
44104433
filtered_paths.append(path)
4411-
if not all(non_in_service_list):
4434+
elif not all(non_in_service_list) or any(
4435+
Path(path).name in filtered_path for filtered_path in filtered_paths
4436+
):
44124437
duplicated_paths.append(path)
44134438

44144439
self._images_to_upload = list(set(filtered_paths)), duplicated_paths
@@ -4447,7 +4472,9 @@ def execute(self):
44474472
],
44484473
annotation_status=self._annotation_status,
44494474
).execute()
4450-
4475+
if response.errors:
4476+
logger.error(response.errors)
4477+
continue
44514478
attachments, attach_duplications = response.data
44524479
uploaded.extend(attachments)
44534480
duplications.extend(attach_duplications)
@@ -4554,24 +4581,6 @@ def execute(self):
45544581
folder_id=self._folder_id,
45554582
images=self._images[i : i + self._chunk_size],
45564583
)
4557-
res += [
4558-
ImageEntity(
4559-
uuid=image["id"],
4560-
name=image["name"],
4561-
path=image["name"],
4562-
project_id=image["project_id"],
4563-
team_id=image["team_id"],
4564-
annotation_status_code=image["annotation_status"],
4565-
folder_id=image["folder_id"],
4566-
annotator_id=image["annotator_id"],
4567-
annotator_name=image["annotator_name"],
4568-
qa_id=image["qa_id"],
4569-
qa_name=image["qa_name"],
4570-
entropy_value=image["entropy_value"],
4571-
approval_status=image["approval_status"],
4572-
is_pinned=image["is_pinned"],
4573-
)
4574-
for image in images
4575-
]
4584+
res += [ImageEntity.from_dict(**image) for image in images]
45764585
self._response.data = res
45774586
return self._response

src/superannotate/lib/infrastructure/controller.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,11 @@ def _get_image(
542542
) -> ImageEntity:
543543
folder = self._get_folder(project, folder_path)
544544
use_case = usecases.GetImageUseCase(
545-
project=project, folder=folder, image_name=image_name, images=self.images,
545+
service=self._backend_client,
546+
project=project,
547+
folder=folder,
548+
image_name=image_name,
549+
images=self.images,
546550
)
547551
return use_case.execute().data
548552

src/superannotate/lib/infrastructure/services.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ def set_images_statuses_bulk(
632632
"image_names": image_names,
633633
},
634634
)
635-
return res
635+
return res.ok
636636

637637
def get_bulk_images(
638638
self, project_id: int, team_id: int, folder_id: int, images: List[str]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"id":4770,"project_id":1176,"name":"Personal vehicle","color":"#ecb65f","count":0,"createdAt":"2020-03-26T11:11:51.000Z","updatedAt":"2020-03-26T11:11:51.000Z","attribute_groups":[]},{"id":4771,"project_id":1176,"name":"Large vehicle","color":"#737b28","count":0,"createdAt":"2020-03-26T11:11:51.000Z","updatedAt":"2020-03-26T11:11:51.000Z","attribute_groups":[]},{"id":4772,"project_id":1176,"name":"Human","color":"#e4542b","count":0,"createdAt":"2020-03-26T11:11:51.000Z","updatedAt":"2020-03-26T11:11:51.000Z","attribute_groups":[]}]
209 KB
Loading

0 commit comments

Comments
 (0)