Skip to content

Commit da195c5

Browse files
committed
Repeat validation in convert_deserialized_civ_data
1 parent c8e8f50 commit da195c5

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

app/grandchallenge/components/serializers.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,39 @@ def convert_deserialized_civ_data(*, deserialized_civ_data):
3131
"""Takes deserialized CIV data and returns list of CIVData objects."""
3232
civ_data_objects = []
3333
for civ in deserialized_civ_data:
34+
if "interface" not in civ:
35+
raise serializers.ValidationError("An interface must be specified")
36+
37+
possible_keys = [
38+
"image",
39+
"value",
40+
"file",
41+
"user_upload",
42+
"upload_session",
43+
("image_name", "user_uploads"),
44+
]
45+
3446
interface = civ["interface"]
3547

3648
keys = set(civ.keys()) - {"interface"}
3749

50+
if not keys:
51+
raise serializers.ValidationError(
52+
f"You must provide at least one of {possible_keys}."
53+
)
54+
3855
keys_not_none = {key for key in keys if civ[key] is not None}
3956

40-
if keys_not_none == {"image_name", "user_uploads"}:
41-
value = DICOMUploadWithName(
42-
name=civ["image_name"],
43-
user_uploads=civ["user_uploads"],
44-
)
57+
if len(keys_not_none) > 1:
58+
if keys_not_none == {"image_name", "user_uploads"}:
59+
value = DICOMUploadWithName(
60+
name=civ["image_name"],
61+
user_uploads=civ["user_uploads"],
62+
)
63+
else:
64+
raise serializers.ValidationError(
65+
f"You can only provide one of {possible_keys} for each socket."
66+
)
4567
elif not keys_not_none:
4668
value = None
4769
else:

0 commit comments

Comments
 (0)