Skip to content

cvat-sdk: Fix creating tasks with non-local files #5058

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

Merged
merged 2 commits into from
Oct 7, 2022
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ non-ascii paths while adding files from "Connected file share" (issue #4428)
- Invisible label item in label constructor when label color background is white,
or close to it (<https://github.com/opencv/cvat/pull/5041>)
- Fixed cvat-core ESlint problems (<https://github.com/opencv/cvat/pull/5027>)
- Fixed task creation with non-local files via the SDK/CLI
(<https://github.com/opencv/cvat/issues/4962>)

### Security
- TDB
Expand Down
5 changes: 2 additions & 3 deletions cvat-sdk/cvat_sdk/core/proxies/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ def upload_data(
if resource_type is ResourceType.LOCAL:
pass # handled later
elif resource_type is ResourceType.REMOTE:
data = {f"remote_files[{i}]": f for i, f in enumerate(resources)}
data["remote_files"] = resources
elif resource_type is ResourceType.SHARE:
data = {f"server_files[{i}]": f for i, f in enumerate(resources)}
data["server_files"] = resources

data["image_quality"] = 70
data.update(
Expand All @@ -104,7 +104,6 @@ def upload_data(
self.api.create_data(
self.id,
data_request=models.DataRequest(**data),
_content_type="multipart/form-data",
)
elif resource_type == ResourceType.LOCAL:
url = self._client.api_map.make_endpoint_url(
Expand Down
4 changes: 2 additions & 2 deletions tests/docker-compose.file_share.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3.3'
services:
cvat_worker_default:
volumes:
- ./tests/cypress/integration/actions_tasks3/assets/case_107:/home/django/share:rw
- ./tests/mounted_file_share:/home/django/share:rw
cvat_server:
volumes:
- ./tests/cypress/integration/actions_tasks3/assets/case_107:/home/django/share:rw
- ./tests/mounted_file_share:/home/django/share:rw
17 changes: 17 additions & 0 deletions tests/python/sdk/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,23 @@ def test_can_create_task_with_local_data(self):
assert "100%" in pbar_out.getvalue().strip("\r").split("\r")[-1]
assert self.stdout.getvalue() == ""

def test_can_create_task_with_remote_data(self):
task = self.client.tasks.create_from_data(
spec={
"name": "test_task",
"labels": [{"name": "car"}, {"name": "person"}],
},
resource_type=ResourceType.SHARE,
resources=["image_case_107_2.png", "image_case_107_1.png"],
# make sure string fields are transferred correctly;
# see https://github.com/opencv/cvat/issues/4962
data_params={"sorting_method": "lexicographical"},
)

assert task.size == 2
assert task.get_frames_info()[0].name == "image_case_107_1.png"
assert self.stdout.getvalue() == ""

def test_cant_create_task_with_no_data(self):
pbar_out = io.StringIO()
pbar = make_pbar(file=pbar_out)
Expand Down
1 change: 1 addition & 0 deletions tests/python/shared/fixtures/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
osp.join(CVAT_ROOT_DIR, dc_file)
for dc_file in (
"docker-compose.dev.yml",
"tests/docker-compose.file_share.yml",
"tests/docker-compose.minio.yml",
"tests/docker-compose.webhook.yml",
)
Expand Down