form.save() exceptions should be more informative
|Reported by:||to.roma.from.djbug@…||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Currently form.save() raises a ValueError if !form.is_valid(). I suggest it should throw some exception from which form.errors could be extracted.
I have this workaround:
def enforce_valid(form): if not form.is_valid(): raise invalid_form(form.errors) return form ... enforce_valid(some_form(...)).save() ...
and also there’s code that catches the custom exception and puts the errors into a session variable and redirects back to the originating page and shows the errors there.
Why does form.save() only provide a message that something went wrong and not the actual errors? It could raise an exception derived from ValueError that would contain the list of errors.