Re: [Django] #9373: "This field is required" error even on empty inlines formsets in the admin model page, when hiding a choice field of a custom form.

46 views
Skip to first unread message

Django

unread,
Feb 2, 2014, 4:34:45 PM2/2/14
to django-...@googlegroups.com
#9373: "This field is required" error even on empty inlines formsets in the admin
model page, when hiding a choice field of a custom form.
--------------------------------+---------------------------------------
Reporter: tyrion.mx@… | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.7-alpha-1
Severity: Normal | Resolution:
Keywords: admin, inlines | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+---------------------------------------
Changes (by Siecje):

* keywords: => admin, inlines
* version: 1.0 => 1.7-alpha-1


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

Django

unread,
May 16, 2014, 9:47:40 AM5/16/14
to django-...@googlegroups.com
#9373: "This field is required" error even on empty inlines formsets in the admin
model page, when hiding a choice field of a custom form.
--------------------------------+---------------------------------------
Reporter: tyrion.mx@… | Owner: schacki
Type: Bug | Status: assigned

Component: Forms | Version: 1.7-alpha-1
Severity: Normal | Resolution:
Keywords: admin, inlines | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+---------------------------------------
Changes (by schacki):

* status: new => assigned
* owner: nobody => schacki


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

Django

unread,
May 17, 2014, 8:11:45 AM5/17/14
to django-...@googlegroups.com
#9373: "This field is required" error even on empty inlines formsets in the admin
model page, when hiding a choice field of a custom form.
--------------------------------+---------------------------------------
Reporter: tyrion.mx@… | Owner: schacki
Type: Bug | Status: assigned
Component: Forms | Version: 1.7-alpha-1
Severity: Normal | Resolution:
Keywords: admin, inlines | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+---------------------------------------

Comment (by anonymous):

I could verify this issue for 1.7-beta. However, the root cause is not
related to Inlines. So let me set up a new example to explain in more
detail:

{{{
# models.py
from django.db import models

class MyModel(models.Model):
a = models.CharField(max_length=10)

# forms.py
from django import forms
from . import models

DUMMY_CHOICES = (
(0, 'x'),
(1, 'y'),
(2, 'z')
)

class MyForm(forms.ModelForm):
b = forms.IntegerField(label='d', initial=0,
widget=forms.Select(choices=DUMMY_CHOICES))
class Meta:
model = models.MyModel

# admin.py
from django.contrib import admin
from . import models, forms

class MyAdmin(admin.ModelAdmin):
model = models.MyModel
form = forms.MyForm
fields = ['a']

admin.site.register(models.MyModel, MyAdmin)
}}}


'''1. MyForm'''
The resulting form MyForm would have the form fields 'a' and 'b'. This
behavior is documented and supposed to be like that.

'''2. MyAdmin Form'''
MyAdmin has the form attribute. This form contains the fields 'a' and 'b'.
At the same time it has the fields attribute, which only refers to 'a'.
This seemingly contradictory information is resolved as follows: the
AdminModel calls the modelform_factory with form=MyForm and fields=['a'].
The modelform_ factory works like a normal ModelForm described in 1. I.e.
the resulting form contains the the fields 'a' and 'b'

'''3. MyAdmin rendering'''
However, for rendering, the ModelAdmin refers either to its field or
fieldsets attribute. Thus, the field 'b' will not be rendered, also it is
available in the form.

'''4. MyAdmin Form Validation'''
For any kind of validation, the generated form with fields 'a' and 'b' is
used, also only field 'a' was available in the rendered form. This
conflict has generated the issue, that has been described in the ticket.


Bottom line: the behavior is as implemented (possibly as expected by the
experts) and there are numerous situations, where it is required, e.g.
UserAdmin. Nevertheless, this behavior is not expected and very hard to
anticipate, especially by beginners. And debugging is very, very
difficult, since it reveals itself only very late in the form handling
process.


Possible resolutions:

'''A. Won't Fix'''
A "won't fix" is therefore not appropriate.

'''B. Raise Warning'''
It could be checked during the ModelAdmin instantiation, if we have less
fields for display than we we have in the form and raise a warning.
However, this would annoy people, who set it up like that on purpose.

'''C. Raise Error'''
Like B, but raise an error; wich backwards incompatible and probably not
worth the effort

'''D. Implement a Check'''
A check (as part of the 1.7 application check), could identify such
situations and raise warnings. I am not sure if and how this would be
possible (never done it).

'''E. Amending fields/fieldsets/exclude'''
If a check identifies the mismatch between admin fields and formfields, we
could:
a) add the missing field(s) to the admin fields list
b) add the missing field(s) to the admin formfields; however this could
only be a plug, since it is not clear, where to add it in the fieldsets
c) add the missing field(s) to the admin exclude list, since exclude takes
precedence.
All 3 options might be backwards incompatible

'''F. Amending form generation'''
If a check identifies the mismatch between admin fields and formfields, we
could adapt the provided form such that the critical field(s) is removed
from the form. This might be backwards incompatible.

--
Ticket URL: <https://code.djangoproject.com/ticket/9373#comment:7>

Django

unread,
May 19, 2014, 10:56:52 AM5/19/14
to django-...@googlegroups.com
#9373: "This field is required" error even on empty inlines formsets in the admin
model page, when hiding a choice field of a custom form.
--------------------------------+---------------------------------------
Reporter: tyrion.mx@… | Owner: schacki
Type: Bug | Status: assigned
Component: contrib.admin | Version: 1.7-alpha-1

Severity: Normal | Resolution:
Keywords: admin, inlines | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+---------------------------------------
Changes (by schacki):

* component: Forms => contrib.admin


--
Ticket URL: <https://code.djangoproject.com/ticket/9373#comment:8>

Django

unread,
May 19, 2014, 10:59:34 AM5/19/14
to django-...@googlegroups.com
#9373: "This field is required" error even on empty inlines formsets in the admin
model page, when hiding a choice field of a custom form.
--------------------------------+---------------------------------------
Reporter: tyrion.mx@… | Owner: schacki
Type: Bug | Status: assigned
Component: contrib.admin | Version: 1.7-alpha-1
Severity: Normal | Resolution:
Keywords: admin, inlines | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+---------------------------------------

Comment (by schacki):

I have just reviewed the new check framework
https://docs.djangoproject.com/en/1.7/topics/checks/. I think we should
add a check in the admin for this situation. The advantage is that this
check is only done with DEBUG=False. I.e. log files are not populated in
production systems.

I am happy to implement this, if the approach is approved.

--
Ticket URL: <https://code.djangoproject.com/ticket/9373#comment:9>

Django

unread,
Dec 18, 2014, 4:40:02 PM12/18/14
to django-...@googlegroups.com
#9373: "This field is required" error even on empty inlines formsets in the admin
model page, when hiding a choice field of a custom form.
--------------------------------+------------------------------------
Reporter: tyrion.mx@… | Owner: schacki
Type: Bug | Status: assigned
Component: contrib.admin | Version: 1.7
Severity: Normal | Resolution:
Keywords: admin, inlines | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by timgraham):

* version: 1.7-alpha-1 => 1.7


--
Ticket URL: <https://code.djangoproject.com/ticket/9373#comment:10>

Django

unread,
Mar 25, 2024, 7:17:16 AM3/25/24
to django-...@googlegroups.com
#9373: "This field is required" error even on empty inlines formsets in the admin
model page, when hiding a choice field of a custom form.
--------------------------------+------------------------------------
Reporter: tyrion.mx@… | Owner: (none)
Type: Bug | Status: new
Component: contrib.admin | Version: 1.7
Severity: Normal | Resolution:
Keywords: admin, inlines | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* owner: schacki => (none)
* status: assigned => new

--
Ticket URL: <https://code.djangoproject.com/ticket/9373#comment:11>
Reply all
Reply to author
Forward
0 new messages