Merge ValidateModelVersion into (Partial)UpdateModelVersion
https://redmine.teklia.com/issues/6994
Sentry Issue: ARKINDEX-BACKEND-1YN
KeyError: 'request'
(5 additional frame(s) were not displayed)
...
File "arkindex/training/api.py", line 347, in post
File "arkindex/training/serializers.py", line 218, in __init__
ValidateModelVersion has never been able to return a success response ever since it was implemented. Instead of fixing it, we can replace it by making the hash, archive_hash, size and state fields available in (Partial)UpdateModelVersion.
When setting hash, if a version with that hash already exists in the database, an HTTP 400 error should occur with the id of the existing element, as we already do in other endpoints like with worker configurations, and not an HTTP 409.
The state can only be updated from created to available. When this update occurs, the archive_hash and size are checked against S3 with ModelVersion.perform_check() and ModelVersion.check_hash(). If those fail, an HTTP 400 error occurs.
Any other state transition is forbidden, and also results in an HTTP 400, not an HTTP 403.
When a ModelVersion is archived, updating the hash, archive_hash, size or state should cause HTTP 400 errors. We cannot forbid updates at all, since that would otherwise prevent a ModelVersion from being unarchived.
If it is more complicated to only have those fields available in updates than having them in both creation and updates, then just make them available on creation, with the same checks.