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

POST does not return the etag recorded in MongoDB #1206

Closed
vbisserie opened this issue Nov 6, 2018 · 1 comment
Closed

POST does not return the etag recorded in MongoDB #1206

vbisserie opened this issue Nov 6, 2018 · 1 comment

Comments

@vbisserie
Copy link

@vbisserie vbisserie commented Nov 6, 2018

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
@vbisserie
Copy link
Author

@vbisserie vbisserie commented Nov 6, 2018

Related to #590

Same analysis than @shtratos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant