Skip to content

Commit

Permalink
Fix #457, bugfix for group checking
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiaskoenig committed Nov 1, 2019
1 parent a86b796 commit b25ff60
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions backend/pkdb_app/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,14 +548,14 @@ def to_internal_related_fields(self, data):
Q(ex__groupset__study__sid=study_sid)
& Q(name=data.get("group"))
).pk

except (ObjectDoesNotExist, MultipleObjectsReturned) as err:
if err == ObjectDoesNotExist:
msg = f'group <{data.get("group")}> does not exist, check groups.'
else:
msg = f'group <{data.get("group")}> is defined multiple times.'

raise serializers.ValidationError(msg)
except ObjectDoesNotExist:
raise serializers.ValidationError(
f'group <{data.get("group")}> does not exist, check groups.'
)
except MultipleObjectsReturned:
raise serializers.ValidationError(
f'group <{data.get("group")}> is defined multiple times.'
)

if "individual" in data:
if data["individual"]:
Expand All @@ -568,14 +568,17 @@ def to_internal_related_fields(self, data):
).pk

except ObjectDoesNotExist:
msg = f'individual: individual <{data.get("individual")}> does not exist, check individuals.'
raise serializers.ValidationError(msg)
raise serializers.ValidationError(
f'individual: individual <{data.get("individual")}> does '
f'not exist, check individuals.'
)
except MultipleObjectsReturned:
msg = f'individual: individual <{data.get("individual")}> is defined multiple times'
raise serializers.ValidationError(msg)
raise serializers.ValidationError(
f'individual: individual <{data.get("individual")}> is '
f'defined multiple times'
)

if "interventions" in data:

if data["interventions"]:
interventions = []
if isinstance(data["interventions"], str):
Expand All @@ -590,8 +593,9 @@ def to_internal_related_fields(self, data):
).pk
)
except ObjectDoesNotExist:
msg = f"intervention <{intervention}> does not exist, check interventions."
raise serializers.ValidationError(msg)
raise serializers.ValidationError(
f"intervention <{intervention}> does not exist, check interventions."
)
data["interventions"] = interventions
return data

Expand Down

0 comments on commit b25ff60

Please sign in to comment.