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

SDK task.upload_data() cannot be used with resources of the Path type #9072

Closed
2 tasks done
zhiltsov-max opened this issue Feb 6, 2025 · 6 comments · Fixed by #9114
Closed
2 tasks done

SDK task.upload_data() cannot be used with resources of the Path type #9072

zhiltsov-max opened this issue Feb 6, 2025 · 6 comments · Fixed by #9114
Assignees
Labels
bug Something isn't working Easy to fix The issue is easy to fix and probably it will be release in a next minor release

Comments

@zhiltsov-max
Copy link
Contributor

zhiltsov-max commented Feb 6, 2025

Actions before raising this issue

  • I searched the existing issues and did not find anything similar.
  • I read/searched the docs

Steps to Reproduce

SDK has a Task.upload_data(), which claims to support StrPath-typed resources, but it is actually only works for LOCAL resource_type.

resources: Sequence[StrPath],

Expected Behavior

Task should be created.

Possible Solution

Remove invalid error here:

for resource in resources:
if not isinstance(resource, str):
raise TypeError(f"resources: expected instances of str, got {type(resource)}")
, replace it with a type conversion.

Context

No response

Environment

@zhiltsov-max zhiltsov-max added bug Something isn't working Easy to fix The issue is easy to fix and probably it will be release in a next minor release labels Feb 6, 2025
@Eslam-Radwan
Copy link

Eslam-Radwan commented Feb 7, 2025

what should I do to face the bug

and what does this line print when the bug happens

raise TypeError(f"resources: expected instances of str, got {type(resource)}")

@zhiltsov-max
Copy link
Contributor Author

Ax example:

from pathlib import PurePosixPath
from cvat_sdk import make_client, models
from cvat_sdk.core.proxies.tasks import ResourceType


with make_client("http://localhost", port=8080, credentials=("user", "pass")) as client:
    task = client.tasks.create_from_data(
        spec=models.TaskWriteRequest(
            name="image task with cs",
            labels=[{"name": "cat"}],
        ),
        resources=[PurePosixPath("image1.png"), PurePosixPath("image2.png")],
        resource_type=ResourceType.SHARE,
        data_params=dict(
            cloud_storage_id=your_cloud_storage_id,
            image_quality=70,
        ),
    )

@Eslam-Radwan
Copy link

Eslam-Radwan commented Feb 7, 2025

can't we just replace

from _typeshed import StrPath, SupportsWrite

with

from _typeshed import SupportsWrite
from os import PathLike

@zhiltsov-max
Copy link
Contributor Author

zhiltsov-max commented Feb 7, 2025

Doing so won't change the error. The function still fails when Path-s are passed.

@RavinduWeerakoon
Copy link
Contributor

So, we need to add logic for type conversions inside the for loop, such as converting Posix to string, right? If that's the case, I'd love to take care of it!

@RavinduWeerakoon
Copy link
Contributor

So, we need to add logic for type conversions inside the for loop, such as converting Posix to string, right? If that's the case, I'd love to take care of it!

So can you assign this issue to me. I have set the development environment according to the guidelines. And I guess there won't be an issue with the os.path since it is already treated as strings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Easy to fix The issue is easy to fix and probably it will be release in a next minor release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants