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
Expected Behavior
Element returned in response of a POST request shall have same
_etagvalue than the document in the DB.In order to reproduce this, you need to set at least
OPLOG_CHANGE_METHODS=['POST']insettings.pyBug source suggestion
In method
oplog_push(eve.methods.common) the document copy is not a deep one and when attribute_updatedand_etagare 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 (_idand_updatedhave changed)This happen especially for POST because argument
documentofoplog_pushis a list. Transformationupdates = [updates]is not executed so deletion onupdateshas impact ondocumentWorkaround
Add
{'etag_ignore_fields': ['_id', 'updated_at']}in Item Endpoints definition.Environment