Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: LEAP-1023: Fix misspelled LocalFilesImportStorageLink in remove_duplicates #5758

Merged
merged 4 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions label_studio/data_manager/actions/remove_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from data_manager.actions.basic import delete_tasks
from io_storages.azure_blob.models import AzureBlobImportStorageLink
from io_storages.gcs.models import GCSImportStorageLink
from io_storages.localfiles.models import LocalFilesImportStorage
from io_storages.localfiles.models import LocalFilesImportStorageLink
from io_storages.redis.models import RedisImportStorageLink
from io_storages.s3.models import S3ImportStorageLink
from tasks.models import Task

Expand Down Expand Up @@ -135,8 +136,8 @@ def restore_storage_links_for_duplicated_tasks(duplicates) -> None:
'io_storages_s3importstoragelink': S3ImportStorageLink,
'io_storages_gcsimportstoragelink': GCSImportStorageLink,
'io_storages_azureblobimportstoragelink': AzureBlobImportStorageLink,
'io_storages_localfilesimportstoragelink': LocalFilesImportStorage,
# 'io_storages_redisimportstoragelink',
'io_storages_localfilesimportstoragelink': LocalFilesImportStorageLink,
'io_storages_redisimportstoragelink': RedisImportStorageLink,
# 'lse_io_storages_lses3importstoragelink' # not supported yet
}

Expand Down
24 changes: 19 additions & 5 deletions label_studio/tests/data_manager/test_api_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

import pytest
from django.db import transaction
from io_storages.azure_blob.models import AzureBlobImportStorage, AzureBlobImportStorageLink
from io_storages.gcs.models import GCSImportStorage, GCSImportStorageLink
from io_storages.localfiles.models import LocalFilesImportStorage, LocalFilesImportStorageLink
from io_storages.redis.models import RedisImportStorage, RedisImportStorageLink
from io_storages.s3.models import S3ImportStorage, S3ImportStorageLink
from projects.models import Project

Expand Down Expand Up @@ -96,10 +100,20 @@ def test_action_delete_all_annotations(tasks_count, annotations_count, predictio


@pytest.mark.django_db
def test_action_remove_duplicates(business_client, project_id):
@pytest.mark.parametrize(
'storage_model, link_model',
[
(AzureBlobImportStorage, AzureBlobImportStorageLink),
(GCSImportStorage, GCSImportStorageLink),
(S3ImportStorage, S3ImportStorageLink),
(LocalFilesImportStorage, LocalFilesImportStorageLink),
(RedisImportStorage, RedisImportStorageLink),
],
)
def test_action_remove_duplicates(business_client, project_id, storage_model, link_model):
# Setup
project = Project.objects.get(pk=project_id)
storage = S3ImportStorage.objects.create(project=project)
storage = storage_model.objects.create(project=project)

# task 1: add not a duplicated task
task_data = {'data': {'image': 'normal.jpg'}}
Expand All @@ -117,22 +131,22 @@ def test_action_remove_duplicates(business_client, project_id):
# task 4: add duplicated task, with storage link and one annotation
task4 = make_task(task_data, project)
make_annotation({'result': []}, task4.id)
S3ImportStorageLink.objects.create(task=task4, key='duplicated.jpg', storage=storage)
link_model.objects.create(task=task4, key='duplicated.jpg', storage=storage)

# call the "remove duplicated tasks" action
status = business_client.post(
f'/api/dm/actions?project={project_id}&id=remove_duplicates',
json={'selectedItems': {'all': True, 'excluded': []}},
)

# as the result, we should have only 2 tasks left:
# As the result, we should have only 2 tasks left:
# task 1 and task 3 with storage link copied from task 4
assert list(project.tasks.order_by('id').values_list('id', flat=True)) == [
task1.id,
task3.id,
]
assert status.status_code == 200
assert S3ImportStorageLink.objects.count() == 1
assert link_model.objects.count() == 1
assert project.annotations.count() == 4
assert project.tasks.count() == 2

Expand Down
Loading