#1390·eve

put_internal doesn't skip validation on insert when skip_validation=True

Author: absassiCreated May 8, 2020Updated May 5, 2022
Labelsstale

I would like to insert or update an item from internal server code, but the resource is complex and I don't want to replicate all the logic in Eve for timestamps, soft delete, media files, etc. in the application, so I'm trying to use eve.methods.put.put_internal for this. However, some of the fields changed from the server are marked read-only (as the client shouldn't be able to change them), so I want to skip validation (and also because I know the data is valid, so validation is redundant in this case).

Unfortunately, put_internal isn't skipping validation on insert when skip_validation=True, because it simply calls post_internal in eve/methods/put.py:153, but the skip_validation parameter is not forwarded to post_internal.

Of course, there are workarounds:

  • Check if the document exists first and then call post_internal directly passing skip_validation=True, but that means two queries in case of updates, because put_internal will make another one anyway.
  • Define an internal resource using the same collection as data source, with less strict validation rules and use that resource instead.
  • Replicate all the relevant logic from Eve in the application, calling app.data.insert and app.data.replace (or app.data.update) directly.

Expected Behavior

Calling put_internal with skip_validation=True should always skip validation.

Actual Behavior

Validation is skipped for updates, but not for inserts.

Environment

  • Python version: 3.6
  • Eve version: 1.1