Skip to content

POST does not return the etag recorded in MongoDB #1206

@vbisserie

Description

@vbisserie

Expected Behavior

Element returned in response of a POST request shall have same _etag value than the document in the DB.

In order to reproduce this, you need to set at least OPLOG_CHANGE_METHODS=['POST'] in settings.py

import requests
from pymongo import MongoClient

resp = requests.post('http://localhost:5000/foo', data={'name': 'bar'})
etag_resp = resp.json()['_etag']

client = MongoClient('mongodb://localhost:27017')
db = client['eve']
col = db['foo']
doc = col.find_one({'name': 'bar'})
etag_db = doc['_etag']

assert etag_resp == etag_db  #Will fail

Bug source suggestion

In method oplog_push (eve.methods.common) the document copy is not a deep one and when attribute _updated and _etag are deleted from the copy, they are deleted from the document too.
They are recomputed after (build_response_document) but not with the exact same element (_id and _updated have changed)

This happen especially for POST because argument document of oplog_push is a list. Transformation updates = [updates] is not executed so deletion on updates has impact on document

Workaround

Add {'etag_ignore_fields': ['_id', 'updated_at']} in Item Endpoints definition.

Environment

  • Python version: 3.6.7
  • Eve version: 0.8.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions