Pregunta

I've found a behavior that looks not good too: I updated a record using python-eve, there was an error because I sent some fields that shouldn't be send, but it was not the problem. I found that even there was an error and the response body show a message relative to it the http response status was 200.
I'm not sure if it is a bug or it is the standard behavior, I expected to receive some 4xx error when validation fails.

Any idea?
Thanks
Gaston

Request URL:http://127.0.0.1:5000/players/52ed7a53a54d75bf68c1b720
Request Method:PUT
Status Code:200 OK
Request Headersview source
    Accept:application/json, text/javascript, */*; q=0.01
    Accept-Encoding:gzip,deflate,sdch
    Accept-Language:en-US,en;q=0.8,es;q=0.6
    Authorization:Basic YWRtaW46c2VjcmV0
    Cache-Control:no-cache
    Connection:keep-alive
    Content-Length:335
    Content-Type:application/json
    Cookie:roles="[\"operator\"\054\"admin\"]"
    Host:127.0.0.1:5000
    If-Match:eeadcc62ad252697c9b109c00cae771c0690c172
    Origin:http://127.0.0.1:5000
    Pragma:no-cache
    Referer:http://127.0.0.1:5000/static/index.html
    User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.77 Safari/537.36
    X-Requested-With:XMLHttpRequest
        Request Payloadview source
        {_updated:2014-02-01T22:50:59.000Z, name:gas1e, score:260, _tenant:tonga.net,…}
        _created: "2014-02-01T22:50:59.000Z"
        _etag: "eeadcc62ad252697c9b109c00cae771c0690c172"
        _issues: {_updated:unknown field, _created:unknown field, _status:unknown field, _issues:unknown field,…}
        _status: "ERR"
        _tenant: "tonga.net"
        _updated: "2014-02-01T22:50:59.000Z"
        name: "gas1e"
        score: 260
Response Headersview source
    Access-Control-Allow-Headers:
    Access-Control-Allow-Max-Age:21600
    Access-Control-Allow-Methods:HEAD, GET, PUT, POST, DELETE, OPTIONS, PATCH
    Access-Control-Allow-Origin:*
    Content-Length:171
    Content-Type:application/json
    Date:Sun, 02 Feb 2014 05:16:09 GMT
    Server:Werkzeug/0.9.4 Python/2.7.5
    Response Payloadview source
        _issues: {_updated:unknown field, _created:unknown field, _status:unknown field, _issues:unknown field,…}
        _created: "unknown field"
        _etag: "unknown field"
        _issues: "unknown field"
        _status: "unknown field"
        _updated: "unknown field"
        _status: "ERR"
¿Fue útil?

Solución

Eve supports bulk inserts, which means that a POST can (and usually will) contain multiple documents submitted for insertion. Some of these document may pass validation and will be inserted, others might fail validation. This is why you get a 200 (request was accepted and processed) and an array with the payload. Each array item contains the id, etag, creation date of the successfully inserted document or, if validation failed, the reason why the document didn't pass it.

This said, I'm considering making bulk insert optional, which would make returning a 4xx on the single document validation failure perfectly reasonable.

Otros consejos

The documentation seems to point to this type of action being exactly what happens.

http://python-eve.org/features.html#data-validation

I have never used this so I can't be much more help on it. But based on what the link above describes this does not seem very RESTful to me. Much of the reason I tend to build my own interfaces rather than rely on some OOTB product. Sadly I see lots of bad implementations.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top