Skip to content

Commit

Permalink
Don't allow unknown fields when using the API to upload reports
Browse files Browse the repository at this point in the history
  • Loading branch information
medihack committed Jun 15, 2024
1 parent 40005ca commit 139d9db
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions radis/reports/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,10 @@ def to_representation(self, instance: Any) -> Any:
ret["modalities"] = [item["code"] for item in ret["modalities"]]

return ret

def validate(self, attrs: Any) -> Any:
if hasattr(self, "initial_data"):
unknown_keys = set(self.initial_data.keys()) - set(self.fields.keys())
if unknown_keys:
raise ValidationError("Got unknown fields: {}".format(unknown_keys))
return super().validate(attrs)

0 comments on commit 139d9db

Please sign in to comment.