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

Should we return 409 instead of 200 for POST if specified id already exists ? #140

Closed
Natim opened this issue Jul 15, 2015 · 3 comments

Comments

@Natim
Copy link
Member

commented Jul 15, 2015

As per Kinto/kinto.js#14 I tried to raise a 409 on a POST.

The behavior is not the one I was expected:

$ echo '{"data": {"title": "Test"}}' | http --verify no POST https://kinto.dev.mozaws.net/v1/buckets/default/collections/tasks/records --auth natim:HTTP/1.1 201 Created
Access-Control-Expose-Headers: Backoff, Retry-After, Alert
Backoff: 10
Connection: keep-alive
Content-Length: 202
Content-Type: application/json; charset=UTF-8
Date: Wed, 15 Jul 2015 09:38:23 GMT
Server: nginx/1.4.6 (Ubuntu)

{
    "data": {
        "id": "1b719cfb-ff5d-4b86-baf6-1e204245a999", 
        "last_modified": 1436953103016, 
        "title": "Test"
    }, 
    "permissions": {
        "write": [
            "basicauth:df93ca0ecaeaa3126595f6785b39c408be2539173c991a7b2e3181a9826a69bc"
        ]
    }
}
$ echo '{"data": {"id": "1b719cfb-ff5d-4b86-baf6-1e204245a999", "title": "Toto"}}' | http --verify no POST https://kinto.dev.mozaws.net/v1/buckets/default/collections/tasks/records --auth natim:
HTTP/1.1 200 OK
Access-Control-Expose-Headers: Backoff, Retry-After, Alert
Backoff: 10
Connection: keep-alive
Content-Length: 202
Content-Type: application/json; charset=UTF-8
Date: Wed, 15 Jul 2015 09:43:13 GMT
Server: nginx/1.4.6 (Ubuntu)

{
    "data": {
        "id": "1b719cfb-ff5d-4b86-baf6-1e204245a999", 
        "last_modified": 1436953103016, 
        "title": "Test"
    }, 
    "permissions": {
        "write": [
            "basicauth:df93ca0ecaeaa3126595f6785b39c408be2539173c991a7b2e3181a9826a69bc"
        ]
    }
}

As you can see when I try a POST on an existing ID, I get the existing record with a 200.

I was expecting getting a 409 Conflict error with the stored record in the detail field.

@Natim Natim added the bug label Jul 15, 2015

@leplatrem

This comment has been minimized.

Copy link
Contributor

commented Jul 15, 2015

This was already discussed a while ago, and we agreed on returning 200 in this case. Discussion can be reopened, but this is definitely not a bug.

As the Cliquet docs say, a 409 is returned when a field unicity is violated. It won't be the case with Kinto, since there is currently no way to specify field unicity (until schema feature is landed)

@Natim Natim added enhancement and removed bug labels Jul 15, 2015

@Natim

This comment has been minimized.

Copy link
Member Author

commented Jul 15, 2015

Could you link the previous discussion issue?

@Natim Natim added the question label Jul 15, 2015

@leplatrem leplatrem changed the title Handle conflict on POST with ids Should we return 409 instead of 200 for POST when ids already exists ? Aug 14, 2015

@leplatrem leplatrem changed the title Should we return 409 instead of 200 for POST when ids already exists ? Should we return 409 instead of 200 for POST if specified id already exists ? Aug 14, 2015

@leplatrem leplatrem added the protocol label Jan 28, 2016

@Natim

This comment has been minimized.

Copy link
Member Author

commented May 18, 2016

If you wish to have a 409 or something telling you that the record already exists, you should use the If-None-Match: * header in that case the record will be created only if it doesn't already exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.