matthiaskoenig / pkdb

Pharmacokinetics database
https://alpha.pk-db.com
29 stars 6 forks source link

Internal server error: MultipleObjectsReturned - get() returned more than one Choice -- it returned 2! #712

Open matthiaskoenig opened 3 years ago

matthiaskoenig commented 3 years ago
MultipleObjectsReturned at /api/v1/_studies/PKDB00165/
get() returned more than one Choice -- it returned 2!

On /api/v1/_studies/PKDB00165/ /api/v1/_studies/PKDB00191/

 File "/code/pkdb_app/subjects/serializers.py", line 443, in to_internal_value
    return super(serializers.ModelSerializer, self).to_internal_value(data)
  File "/usr/local/lib/python3.7/site-packages/rest_framework/serializers.py", line 490, in to_internal_value
    validated_value = field.run_validation(primitive_value)
  File "/usr/local/lib/python3.7/site-packages/rest_framework/serializers.py", line 621, in run_validation
    value = self.to_internal_value(data)
  File "/usr/local/lib/python3.7/site-packages/rest_framework/serializers.py", line 657, in to_internal_value
    validated = self.child.run_validation(item)
  File "/usr/local/lib/python3.7/site-packages/rest_framework/serializers.py", line 436, in run_validation
    value = self.validate(value)
  File "/code/pkdb_app/subjects/serializers.py", line 103, in validate
    attrs["choice"] = attrs["measurement_type"].validate_complete(data=attrs, time_allowed=False)["choice"]
  File "/code/pkdb_app/info_nodes/models.py", line 379, in validate_complete
    d_choice = self.validate_choice(choice)
  File "/code/pkdb_app/info_nodes/models.py", line 330, in validate_choice
    return self.choices.get(info_node__name=choice)
  File "/usr/local/lib/python3.7/site-packages/django/db/models/query.py", line 436, in get
    num if not limit or num < limit else 'more than %s' % (limit - 1),
matthiaskoenig commented 3 years ago

@janekg89 Add a uniqueness contraint on info_node.name. Also in pkdb_data the uniqueness of names must be checked in the validation of the info nodes.