I need to ensure that whenever a user makes a GET request on a resource, it always includes a particular field called "_mes". This becomes a problem when user specifies a projection, so I am trying to always add it
app.on_pre_GET_my_resource = pre_get_my_resource_callback
...
...
...
def pre_get_my_resource_callback(request, lookup):
"""Always add _mes to projection"""
projection = json.loads(request.args['projection']) if 'projection' in request.args else None
projected_field = True if projection is None or ('_mes' in projection and projection['_mes'] == 1) else False
if not projected_field:
projection['_mes'] = 1
request.args['projection'] = json.dumps(projection)
print(projection)
The problem is that request is inmutable, and therefor it fails
I would not like to repeat exactly the same query by myself and duplicate it, and have to merge both after... I suppose there must be a way provided by Eve to do this, but how?