Opened 6 years ago

Last modified 6 years ago

#29549 closed Cleanup/optimization

ModelForms doesn't validate CHOICES — at Initial Version

Reported by: Evgeny Arshinov Owned by: nobody
Component: Documentation Version: 1.11
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This is basically a sequel of #6967.

For some reason, only form validation was considered in the original ticket, but data validation is not limited to that, but also includes data integrity checks running when one calls model_instance.save().

As a developer, I would expect model_instance.save() to validate the choices field against the list of possible choices, not least because the list is defined at the model level, participates in db migrations etc., so it should take effect on modal instances.

I haven't been able to find any documentation or existing bug reports that clearly state that [choices https://docs.djangoproject.com/en/2.0/ref/models/fields/#choices] argument only affects the corresponding model form field presentation and does not ensure data integrity.

In summary:

  1. I would like to know the rationale for ignoring choices during data integrity checks, in case I am missing something.
  2. Please consider providing an option to turn data integrity check on.
  3. If the current behavior is left intact, it should be explicitly documented in the official documentation.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top