ja_resource
ja_resource copied to clipboard
Validation before delete? Is it necessary
After updating a pretty old project to Ecto 3.4 and Elixir 1.7, I found I had a whole bunch of failing tests anywhere where I was not overriding ja_resource's handle_delete. The reason was this line.
https://github.com/vt-elixir/ja_resource/blob/1035b86e74823b14389e07855d67133bcf4381b5/lib/ja_resource/delete.ex#L51
This was resulting in my controllers returning 422's where 204's were expected due to the record not passing validation (which is part of the changeset function in most cases). I haven't figured out why this changed in my upgrade, but regardless, I wanted to understand why this line is there.
If you are going to delete a record, what is the use in building a changeset from it first? And if it gets marked invalid in that process (for example if the record were created before you added some stricter validations later on), why should that prevent a delete?
I'm going to fork and remove this for now, but I am probably missing something so I would love to discuss if anyone has thoughts on this!