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

[Bug] CLI task create call fails when the project is under an organization #4449

Closed
2 tasks done
neumannjan opened this issue Mar 13, 2022 · 10 comments
Closed
2 tasks done

Comments

@neumannjan
Copy link

neumannjan commented Mar 13, 2022

My actions before raising this issue

When I issue a POST call to /api/tasks to create a task under a certain project, it doesn't allow me to create it under the organization that the project belongs to, even though I, as the task creator, am part of said organization. (I used the CLI and also tried it in Swagger)

Expected Behaviour

python cli.py --auth [...] create --project_id 2 [...] should succeed when project with the supplied ID is under an organization that the user is authorized to create tasks for.

Current Behaviour

The above call fails with status code 400 and the following error:

The task and its project should be in the same organization.

Steps to Reproduce (for bugs)

  1. Create an organization
  2. Create a user that isn't the owner of the orgnaization. Make them staff.
  3. Use cli.py to create a task for the project from the non-owner user
@neumannjan neumannjan changed the title [Bug] CLI task create call fails when the task is under an organization [Bug] CLI task create call fails when the project is under an organization Mar 13, 2022
@pedrofrodenas
Copy link

Yes, I have the same problem. Calling api/tasks with POST method does not allow to include a organization, but when you use GET method the organization field is included. I can't upload tasks via API when the project_id is under a organization.
When the task is created using the Browser UI selecting a organization it can be created but using the API not.

@nmanovic
Copy link
Contributor

Please add ?org=slug where slug is the slug for your org in corresponding API calls. Also it is possible to use X-Organization HTTP header. We are going to improve the documentation and provide some python SDK in the future.

https://github.com/openvinotoolkit/cvat/blob/be334fdee95563b54c011290ffa6b4bbf9fd4296/cvat/apps/iam/views.py#L31

@pedrofrodenas
Copy link

pedrofrodenas commented Mar 31, 2022

Please add ?org=slug where slug is the slug for your org in corresponding API calls. Also it is possible to use X-Organization HTTP header. We are going to improve the documentation and provide some python SDK in the future.

https://github.com/openvinotoolkit/cvat/blob/be334fdee95563b54c011290ffa6b4bbf9fd4296/cvat/apps/iam/views.py#L31

I have tried this:

I have an organization named 'Royo' so slug=Royo,

I have the objective of creating a task using the api POST method. So in order to do that I have built the url for calling the api this way:

http://localhost:8080/api/tasks?org=Royo

Adding '?org=Royo' at the end of the url

It works!

@neumannjan
Copy link
Author

While the REST API supports this, cli.py lacks the support for this, but it should support it as well.

@kimSooHyun950921
Copy link

as explained above,
The cli code was executed by changing the code as shown below.

    with requests.Session() as session:
        session.headers.update({'X-Organization':'org name'})
        api = CVAT_API_V2('%s:%s' % (args.server_host, args.server_port), args.https)
        cli = CLI(session, api, args.auth)
        try:
            actions[args.action](cli, **args.__dict__)
        except (requests.exceptions.HTTPError,
                requests.exceptions.ConnectionError,
                requests.exceptions.RequestException) as e:
            log.critical(e)

@Stanley-Michael
Copy link

Stanley-Michael commented Mar 15, 2023

@kimSooHyun950921 please could you elaborate on what code was changed to the code you have provided, and to what post above explained this

Edit: Temp fix for anyone who needs help getting this working while using CVAT-CLI.

you can change python3.9/site-packages/cvat_sdk/api_client/api_client.py

in the ApiClient class, under the __call_api function, just before "# perform request and return response" you may add the following line:
url=url+'?org={org}'
Where {org} is the name of the organisation you created in CVAT

This will allow you to create tasks using the CLI by appending the required command at the end of your http request.

hope this helps someone

@SpecLad
Copy link
Contributor

SpecLad commented Jun 15, 2023

In the next release, the CLI will have an --organization option, which you can use to set the organization in which the task will be created (see #6317).

I'm not considering this issue fixed, though, since I think it would be useful for CVAT to automatically determine the organization when the task is linked to a project. That will need to be implemented in the server, rather than the CLI.

@hetfmt
Copy link

hetfmt commented Oct 12, 2023

The problem is the same when working with the Python high-level SDK.
Should I create a new bug report, or will the above update to the CLI also address the problem with the Python high-level SDK?

@SpecLad
Copy link
Contributor

SpecLad commented Oct 12, 2023

@hetfmt You can do this with the SDK already; just need to set the organization context. See https://opencv.github.io/cvat/docs/api_sdk/sdk/highlevel-api/#users-and-organizations.

@hetfmt
Copy link

hetfmt commented Oct 13, 2023

@SpecLad Excellent! Thank you! I just tested it, and it works like a charm :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants