Currently, Base.check_m2m_consistency does not trigger on model forms is_valid method. The form.save() method will not insert data (still consistent), however the error is not captured and causes the app to crash. This extends #72.
The clean method for forms should raise a ValidationError and not trigger ConsistencyErrors on save.
Additional context
It seems to me that the only way to ensure that consistency errors are captured and validation errors are raised on clean is to update Djangos ModelMultipleChoiceField. The new ModelMultipleChoiceConsistencyField calls the Base class check_m2m_consistency on clean. Additionally, one needs to update the model-field -> form-field register such that the new ModelMultipleChoiceConsistencyField with consistency checks is rendered on default.
Describe the bug
Currently,
Base.check_m2m_consistency
does not trigger on model formsis_valid
method. The form.save() method will not insert data (still consistent), however the error is not captured and causes the app to crash. This extends #72.To Reproduce
See #76 https://github.com/callat-qcd/espressodb/blob/be3c819a304abb1a2baba4d4569c718cc1d06f5c/tests/espressodb_tests/espressodb_tests/m2mtests/tests.py#L204
Expected behavior
The clean method for forms should raise a ValidationError and not trigger ConsistencyErrors on save.
Additional context
It seems to me that the only way to ensure that consistency errors are captured and validation errors are raised on clean is to update Djangos
ModelMultipleChoiceField
. The newModelMultipleChoiceConsistencyField
calls the Base class check_m2m_consistency on clean. Additionally, one needs to update the model-field -> form-field register such that the new ModelMultipleChoiceConsistencyField with consistency checks is rendered on default.