Skip to content

Commit

Permalink
fix: LEAP-1023: Fix misspelled LocalFilesImportStorageLink in remove_…
Browse files Browse the repository at this point in the history
…duplicates (#5758)

#### Change has impacts in these area(s)
_(check all that apply)_
- [ ] Product design
- [ ] Backend (Database)
- [x] Backend (API)
- [ ] Frontend



### Describe the reason for change
Right now remove duplicates from Local Storages raises error because
there is a misspell in code:

`LocalFilesImportStorageLink` => `LocalFilesImportStorageLink`


#### What does this fix?
Just rename import model. 


#### What is the current behavior?
Remove duplicates from DM actions fails when applied to files from Local
Storage.


### What level of testing was included in the change?
_(check all that apply)_
- [ ] e2e
- [ ] integration
- [ ] unit
  • Loading branch information
makseq committed Apr 19, 2024
1 parent d84b3a8 commit ff7105f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
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

0 comments on commit ff7105f

Please sign in to comment.