Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update method doesn't raise a serializer error on save with invalid data. #304

Open
jalondono opened this issue Apr 1, 2022 · 0 comments

Comments

@jalondono
Copy link

jalondono commented Apr 1, 2022

I am trying to created an object from a nested field, using a patch request. Basically there exist one to many relationship between them, and also a unique together constrain at the model level.

url: PATCH: http://127.0.0.1:8000/api/v2/product_batches/11791/

Payload:

{
    "ingredient_mixes":{
        "create":[{
            "ingredient": 23,
            "quantity": 3,
            "unit_of_measurement": "kg",
            "product_batch": 11791,
            "is_removed": false,
            "removed_at": "2021-11-18T21:58:39.512Z",
            "remote_id": null
        },
        {
            "ingredient": 17,
            "quantity": 100,
            "unit_of_measurement": "L",
            "product_batch": 11791,
            "is_removed": false,
            "removed_at": "2021-11-18T21:58:39.512Z",
            "remote_id": null
        }]
    }
}

When I try to create an object that break the unique together constrain, let's that send again the same payload. The update method, get and an error from the serializer.

Screen Shot 2022-04-01 at 10 42 41 AM

Because the data is not valid, It violates the unique together constrain as I expect, but the request return a 500 code with the following message: "AssertionError: You cannot call .save() on a serializer with invalid data" Instead of return serializers.ValidationError.
Is this behaviour what are you expecting?
I would like to handle that error, I think in override the update method and put one try and except in order to catch the ValidationError and return a custom message.
Do you have any suggestion to this?
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant