Re: [Django] #12627: If all fields are readonly or editable=False, their ModelForm is always valid and can raise exceptions

14 views
Skip to first unread message

Django

unread,
Jul 30, 2012, 11:26:46 AM7/30/12
to django-...@googlegroups.com
#12627: If all fields are readonly or editable=False, their ModelForm is always
valid and can raise exceptions
-------------------------------------+-------------------------------------
Reporter: KyleMac | Owner: anonymous
Type: Bug | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: readonly_fields | Triage Stage: Accepted
editable | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by kitsunde):

* cc: kitsunde@… (added)


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

Django

unread,
Nov 13, 2024, 3:36:16 AM11/13/24
to django-...@googlegroups.com
#12627: If all fields are readonly or editable=False, their ModelForm is always
valid and can raise exceptions
-------------------------------------+-------------------------------------
Reporter: KyleMac | Owner: anonymous
Type: Bug | Status: new
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
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):

* cc: Clifford Gama (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/12627#comment:5>

Django

unread,
Feb 7, 2025, 5:58:57 AM2/7/25
to django-...@googlegroups.com
#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: assigned
Component: contrib.admin | Version: dev
Severity: Normal | Resolution:
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):

* owner: anonymous => Clifford Gama
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/12627#comment:6>

Django

unread,
Apr 15, 2025, 2:02:32 AM4/15/25
to django-...@googlegroups.com
#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>
Reply all
Reply to author
Forward
0 new messages