#12627: If all fields are readonly or editable=False, their ModelForm is always
valid and can raise exceptions
-------------------------------------+-------------------------------------
     Reporter:  KyleMac              |                    Owner:  Clifford
                                     |  Gama
         Type:  Bug                  |                   Status:  closed
    Component:  contrib.admin        |                  Version:  dev
     Severity:  Normal               |               Resolution:  invalid
     Keywords:  readonly_fields      |             Triage Stage:  Accepted
  editable                           |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Clifford Gama):

 * resolution:   => invalid
 * status:  assigned => closed

Comment:

 After reviewing this ticket, it seems clear to me that the reported
 behavior is not a bug in Django; it is a result of the developer's
 misconfiguration or oversight.

 The admin, forms, and model layers are each working as intended:

 `form.is_valid()` only validates editable fields. If none exist, no
 validation is performed, and the form is valid by design. (In other words,
 non-editable fields are always valid.) It does not mean a model is ready
 to save.

 The admin correctly displays only editable fields and readonly fields and
 attempts to save the instance if the form is valid, which it is.

 The `IntegrityError` raised at save time is expected when required fields
 are missing and no defaults are provided for non-nullable fields.
 (Musician works because string-based fields effectively have a default of
 `""`.

 If a model has no editable fields and requires additional values to be
 valid, it is the developer's responsibility to provide them. Django allows
 this to be done by overriding `ModelAdmin.save_model()`, for example,
 which I think serves a similar role to the `save(commit=False)` idiom.

 Therefore, as mentioned, an `IntegrityError` isn't an issue with Django,
 but rather a result of incorrect or incomplete configuration.

 Closing as invalid.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/12627#comment:7>
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 view this discussion visit 
https://groups.google.com/d/msgid/django-updates/01070196380aaf24-358b3507-8cae-4b1c-b24e-7ab93d4655b3-000000%40eu-central-1.amazonses.com.

Reply via email to