Chemical-Curation / chemcurator_django

Backend services for chemical curation
https://api.chemreg.epa.gov
MIT License
1 stars 0 forks source link

Associated compound not 1:1 error message #299

Closed cmgrulke closed 3 years ago

cmgrulke commented 3 years ago

Describe the bug a patch/post to substances that attempts to use an associated_compound that has already been assigned to a substance, the serializer is validating, but the save method throws a 500 server error at the moment

To Reproduce Steps to reproduce the behavior:

  1. Go to 'Postman'
  2. make a POST or PATCH to substances where the associatedCompound is already linked to a substance
  3. See error

Expected behavior The errror coming from the OneToOne field validation should be returned in a 400 response

Additional context

There is a branch(unique-compound-error) that illustrates in tests the problem that we are having with a patch/post to substances that attempts to use an associated_compound that has already been assigned to a substance, the serializer is validating, but the save method throws an error at the moment which you can see in the test_serializers test I've added if you...

pytest --pdb chemreg/substance/tests/test_serializers.py::test_substance_unique_compound

and try the following is_valid() and save() methods in the debugger. Here's what the runserver kicks back

django.db.utils.IntegrityError: duplicate key value violates unique constraint "substance_substance_associated_compound_id_key"
DETAIL:  Key (associated_compound_id)=(DTXCID502000024) already exists.

but in Postman when we try to patch/post witha compound that is already connected to a substance, we are getting...

<!doctype html>
<html lang="en">
<head>
    <title>Server Error (500)</title>
</head>
<body>
    <h1>Server Error (500)</h1>
    <p></p>
</body>
</html>
jtumkur commented 3 years ago
debboutr commented 3 years ago

I made a branch that tests and solves this ticket named unique-compound-error that probably just needs to be updated w/ dev.