[Django] #26844: A formset with only one entry marked for deletion, passes validate_min = True and min_num = 1

14 views
Skip to first unread message

Django

unread,
Jul 6, 2016, 10:21:59 AM7/6/16
to django-...@googlegroups.com
#26844: A formset with only one entry marked for deletion, passes validate_min =
True and min_num = 1
-------------------------------+--------------------
Reporter: wimfeijen | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
validate_min and min_num do not behave as I expected.

Defining a formset like this:

{{{
ImageFormSet = inlineformset_factory(
Room,
Image,
form = ImageForm,
extra = 5,
min_num = 1,
max_num = 5,
validate_min = True,
)

...
image_formset = ImageFormSet(request.POST, request.FILES,
instance=room)

}}}

I filled in image_formset with this data. Note that I am posting one form
with data and four empty forms.

{{{
(Pdb) image_formset.cleaned_data
[{'image': <InMemoryUploadedFile: gras.jpg (image/jpeg)>, 'room': <Room:
Test wim yy>, u'id': None, u'DELETE': True}, {}, {}, {}, {}]

}}}

Due to the empty forms, this passes validation, contrary to my
expectations.

This is because of:
lines 354 and 355 in django/forms/formsets.py

{{{
if (self.validate_min and
self.total_form_count() - len(self.deleted_forms) <
self.min_num):

}}}

and

{{{
(Pdb) image_formset.total_form_count()
5

}}}

total_form_count() turns out to be 5 instead of 1 .

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

Django

unread,
Jul 8, 2016, 7:54:48 PM7/8/16
to django-...@googlegroups.com
#26844: Formset's validate_min doesn't work correctly with deleted forms
---------------------------+------------------------------------
Reporter: wimfeijen | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.9
Severity: Normal | Resolution:
Keywords: | 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):

* needs_better_patch: => 0
* component: Uncategorized => Forms
* needs_tests: => 0
* needs_docs: => 0
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/26844#comment:1>

Django

unread,
Jul 21, 2016, 11:32:08 AM7/21/16
to django-...@googlegroups.com
#26844: Formset's validate_min doesn't work correctly with deleted forms
---------------------------+---------------------------------------
Reporter: wimfeijen | Owner: mpatibandla
Type: Bug | Status: assigned

Component: Forms | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------+---------------------------------------
Changes (by mpatibandla):

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


--
Ticket URL: <https://code.djangoproject.com/ticket/26844#comment:2>

Django

unread,
Jul 21, 2016, 3:37:58 PM7/21/16
to django-...@googlegroups.com
#26844: Formset's validate_min doesn't work correctly with deleted forms
---------------------------+---------------------------------------
Reporter: wimfeijen | Owner: mpatibandla
Type: Bug | Status: assigned
Component: Forms | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------+---------------------------------------
Changes (by timgraham):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/6930 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/26844#comment:3>

Django

unread,
Aug 10, 2016, 12:55:28 PM8/10/16
to django-...@googlegroups.com
#26844: Formset's validate_min doesn't work correctly with empty forms
---------------------------+---------------------------------------------

Reporter: wimfeijen | Owner: mpatibandla
Type: Bug | Status: assigned
Component: Forms | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------+---------------------------------------------
Changes (by timgraham):

* stage: Accepted => Ready for checkin


Comment:

The issue here turns out to be empty forms be included in the form count.

--
Ticket URL: <https://code.djangoproject.com/ticket/26844#comment:4>

Django

unread,
Aug 10, 2016, 1:03:48 PM8/10/16
to django-...@googlegroups.com
#26844: Formset's validate_min doesn't work correctly with empty forms
---------------------------+---------------------------------------------
Reporter: wimfeijen | Owner: mpatibandla
Type: Bug | Status: closed
Component: Forms | Version: 1.9
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------+---------------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"f5c6295797b8332134fd89e0209a18a1d1d45e0c" f5c6295]:
{{{
#!CommitTicketReference repository=""
revision="f5c6295797b8332134fd89e0209a18a1d1d45e0c"
Fixed #26844 -- Made formset's validate_min validation ignore empty forms.
}}}

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

Django

unread,
Apr 25, 2017, 6:27:14 AM4/25/17
to django-...@googlegroups.com
#26844: Formset's validate_min doesn't work correctly with empty forms
----------------------------+---------------------------------------------
Reporter: Wim Feijen | Owner: Manasa Patibandla
Type: Bug | Status: new

Component: Forms | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+---------------------------------------------
Changes (by Jim Ouwerkerk):

* status: closed => new
* resolution: fixed =>


Comment:

Replying to [comment:5 Tim Graham <timograham@…>]:


> In [changeset:"f5c6295797b8332134fd89e0209a18a1d1d45e0c" f5c6295]:
> {{{
> #!CommitTicketReference repository=""
revision="f5c6295797b8332134fd89e0209a18a1d1d45e0c"
> Fixed #26844 -- Made formset's validate_min validation ignore empty
forms.
> }}}

This commit breaks the validate_min validation for formset with existing
unchanged data in Django 1.11.
It counts unchanged existing forms as 'empty' form because they are not
changed, but they should not be counted as empty.

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

Django

unread,
Apr 25, 2017, 9:48:15 AM4/25/17
to django-...@googlegroups.com
#26844: Formset's validate_min doesn't work correctly with empty forms
----------------------------+---------------------------------------------
Reporter: Wim Feijen | Owner: Manasa Patibandla
Type: Bug | Status: closed
Component: Forms | Version: 1.9
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+---------------------------------------------
Changes (by Simon Charette):

* status: new => closed
* resolution: => fixed


Comment:

Jim, please file a new ticket instead of reopening this one. Just make
sure to refer to this ticket to provide context.

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

Django

unread,
Apr 27, 2017, 11:45:41 AM4/27/17
to django-...@googlegroups.com
#26844: Formset's validate_min doesn't work correctly with empty forms
----------------------------+---------------------------------------------
Reporter: Wim Feijen | Owner: Manasa Patibandla
Type: Bug | Status: closed
Component: Forms | Version: 1.9
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------+---------------------------------------------

Comment (by Tim Graham):

The new ticket is #28130.

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

Reply all
Reply to author
Forward
0 new messages