How to disable fields _updated
, _created
, _etag
, _links
?
I want to limit bandwidth and those fields are bigger size than data which I actually need to get from my database (Mongodb)

- 365
- 2
- 10
-
Take a look at http://python-eve.org/config.html#projection – Apr 18 '16 at 10:39
2 Answers
With the exceptions of _links
, which you can remove by disabling HATEOAS (HATEOAS = False
), you can only rename the other meta fields.
While the framework itself won't remove them, you could hook up a custom callback and purge those fields yourself before the response is sent over the wire.
from eve import Eve
def on_fetched_resource(resource, response):
for document in response['_items']:
del(document['_etag'])
# etc.
app = Eve()
app.on_fetched_resource += on_fetched_resource
if __name__ == '__main__':
app.run()

- 6,606
- 1
- 20
- 33
-
1I have the same issue, but the proposed solution doesn't fit my case: I have an existing MysqlDB schema that I cannot change, and I want to use eve-sqlalchemy. So the framework fails on POST PUT requests because there are mo _updated and _created columns... – Maksym Rudenko Nov 13 '19 at 09:54
Good question!
If you not too anxious about concurrency control which is for the user-side integrity, you can disable it, and so the _etag
field. This can be done by adding a simple option in your settings.py
:
IF_MATCH = False
This also may be handy if you want to edit database with an external tools or apps, as it lets you avoid doing additional jiggery-pokery with "_etag".
To understand whether you need ETag, check out: https://docs.python-eve.org/en/stable/features.html#data-integrity-and-concurrency-control
Also refer to Nicola Iarocci, who mentioned about disabling HATEOAS (HATEOAS = False
) and a way to remove _etag
field without disabling ETag checks. (Actually I wonder how you can check and post with latest _etag
then?)

- 66
- 5