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

A user with that username already exists, when create a new project #3818

Closed
2 tasks
CvHadesSun opened this issue Oct 21, 2021 · 5 comments
Closed
2 tasks

Comments

@CvHadesSun
Copy link

CvHadesSun commented Oct 21, 2021

My actions before raising this issue

Allow: GET, POST, HEAD
Content-Type: application/json
Vary: Accept

{
    "owner": {
        "username": [
            "A user with that username already exists."
        ]
    },
    "assignee": {
        "username": [
            "A user with that username already exists."
        ]
    }
}

Expected Behaviour

A project should be created, owned by the provided owner and assigned to the provided assignee.

I am runing the `python manage.py runserver `, and using the REST API `create` to create a new project. the `owner` and `assignee` name are required. and I assign the exists username info, the validation error is : "A user with that username already exists.", but i assign the no exists username, i meet other error: Cannot assign "OrderedDict([('username', 'xxx'), ('first_name', ''), ('last_name', '')])": "Project.assignee" must be a "User" instance. ### Current Behaviour

Possible Solution

Steps to Reproduce (for bugs)

  1. git clone repo.
    2.install requirement python env.
  2. run python manage.py runserver
  3. http://localhost:8080/api/v1/projects
{
    "name": "test",
    "labels": [],
    "owner": {
        "username": "testuser",
        "first_name": "",
        "last_name": ""
    },
    "assignee": {
        "username": "testuser",
        "first_name": "",
        "last_name": ""
    },
    "owner_id": null,
    "assignee_id": null,
    "bug_tracker": "",
    "task_subsets": [],
    "training_project": {
        "host": "test",
        "username": "testuser",
        "password": "testuser",
        "enabled": false,
        "project_class": null
    },
    "dimension": "2D"
}

Context

I want to know: how can I create a new project using rest-framework api?

Your Environment

  • Git hash commit (git log -1):
  • Docker version docker version (e.g. Docker 17.0.05):
  • Are you using Docker Swarm or Kubernetes?
  • Operating System and version (e.g. Linux, Windows, MacOS):
  • Code example or link to GitHub repo or gist to reproduce problem:
  • Other diagnostic information / logs:
    Logs from `cvat` container

Next steps

You may join our Gitter channel for community support.

@bsekachev
Copy link
Member

Hi @CvHadesSun

Try to omit assignee and owner fields, setting owner_id and assignee_id in POST and PATCH requests.

@CvHadesSun
Copy link
Author

Yes, I want to omit two fields, but I set the owner and assignee blank, and get the error:

    "owner": {
        "username": [
            "This field may not be blank."
        ]
    },
    "assignee": {
        "username": [
            "This field may not be blank."
        ]
    }

How should I do to omit two fields and create a new project?

@bsekachev
Copy link
Member

I referred to UI to see what requests it sends to the server:

POST:
image
image

PATCH:
image
image

Try to do the things your are doing this way in two requests.
Owner field is set automatically (owner is a user who sent the POST request), you probably can't set it via API.

@CvHadesSun
Copy link
Author

ok, I understand. Thanks for your reply.

@bsekachev
Copy link
Member

I hope you managed to the issue. I will close it. Do not hesitate to reopen if you still have questions

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

2 participants