#29549: Document that Field.choices are enforced by model validation
-------------------------------------+-------------------------------------
     Reporter:  Evgeny Arshinov      |                    Owner:  Tim
         Type:                       |  Graham
  Cleanup/optimization               |                   Status:  closed
    Component:  Documentation        |                  Version:  1.11
     Severity:  Normal               |               Resolution:  fixed
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by Evgeny Arshinov:

Old 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
> [https://docs.djangoproject.com/en/2.0/ref/models/fields/#choices
> 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.

New 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 model instances.

 I haven't been able to find any documentation or existing bug reports that
 clearly state that
 [https://docs.djangoproject.com/en/2.0/ref/models/fields/#choices 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.

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29549#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.d612533b674b766d9e64067f82591749%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to