MongoEngine / eve-mongoengine

An Eve extension for MongoEngine ODM support
Other
39 stars 28 forks source link

Requests using etag returned by POST is bound to get a 412 #16

Closed blurrcat closed 9 years ago

blurrcat commented 9 years ago

The etag returned by POST is inserted before the a document is saved into DB. So this etag is calculated without the _id field: https://github.com/nicolaiarocci/eve/blob/master/eve/methods/post.py#L225 Though later there's point the document does have _id, the etag is not updated since there's already one. https://github.com/nicolaiarocci/eve/blob/master/eve/methods/common.py#L384

If you use the returned etag here to do another request, a DELETE for example, the etag comparison is bound to fail because the server-side etag is now calculated with _id: https://github.com/nicolaiarocci/eve/blob/master/eve/methods/common.py#L64

Example:

POST /people HTTP/1.1
Content-Type: application/json

{
    "name": "test"
}

Response:

{
    "created_at": "2015-03-26 05:55:17", 
    "updated_at": "2015-03-26 05:55:17", 
    "_links": {"self": {"href": "people/55139f45a54d75532e2ed06f", "title": "People"}}, 
    "_status": "OK", 
    "_id": "55139f45a54d75532e2ed06f", 
    "_etag": "87f7a17318bed13ba0ad0dcd259b3b22a4c9375a"
}

With the above etag:

DELETE /people/55139f45a54d75532e2ed06f HTTP/1.1
Content-Type: application/json
If-Match: 87f7a17318bed13ba0ad0dcd259b3b22a4c9375a

Now we get a 412.

mmellison commented 9 years ago

Under new management!

We are going to be re-writing a significant portion of the extension. Closing issue. When the new version is released and you feel this issue still has not been resolved, please feel free to open the issue.