DeleteView skips validation when using DELETE verb

Hi

I’m currently porting a large Django 3.2 project to 4.2. It does have a couple dozen CBVs that inherit from DeleteView. Many of them override delete() to add additional validation and logging on deletion of objects. As noted in the release notes for Django 4.0, I moved that logic from delete() to form_valid(), which works when using POST.

When I ran the tests, I noticed that the custom logic in form_valid() isn’t called. Turns out that in the test suite, client.delete() is often used in place of client.post(), which ends up calling DeletionMixin.delete(), completely skipping past the validation logic.

I could just replace the client.delete() calls in the test suite with client.post(), but what about actual clients using the DELETE verb when interacting with the app? They could skip validation (knowingly or unknowingly), which seems like a problem to me.

I tried overriding delete(), but then Django yells at me that I shouldn’t override delete() (that stems from a check in BaseDeleteView.__init__).

So far, the only somewhat practical idea I had is to build my own DeleteView that doesn’t include DeletionMixin in the inheritance chain. Am I missing something?

Have you tried passing form_class to the delete view?

I’m not sure how that would help. My concern is that DeletionMixin.delete() deletes the object without any consideration of the form and is called when an HTTP client uses the DELETE verb.

It would be better to provide your tests and describe exactly what is not working.