#30376: Saving ModelForm with missing, non-optional fields does not trigger a
validation error
-------------------------------+--------------------------------------
     Reporter:  Will Gordon    |                    Owner:  nobody
         Type:  Bug            |                   Status:  new
    Component:  Uncategorized  |                  Version:  2.1
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Unreviewed
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------

Comment (by zeynel özdemir):

 As it is written in documentation
 (https://docs.djangoproject.com/en/2.1/topics/forms/modelforms
 /#interaction-with-model-validation):

  As part of the validation process, ModelForm will call the clean() method
 of each field on your model that has a corresponding field on your form.
 If you have excluded any model fields, validation will not be run on those
 fields.

 It is not a bug, it is expected behaviour. `ModelForm` should not care
 about the validation of the fields that are not defined in `fields`
 attribute, since we are explicitly telling it which fields to use.
 Otherwise, it would cause too much confusion.

 And here, it does not say that validation will fail:
  Django will prevent any attempt to save an incomplete model, so if the
 model does not allow the missing fields to be empty, and does not provide
 a default value for the missing fields, any attempt to save() a ModelForm
 with missing fields will fail.

 It says that any attempt to save() a ModelForm with missing fields will
 fail.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30376#comment:1>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.a4161fed8e653c578f93a2046a0106d6%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to