#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.
--
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/052.4e3f5e95da1bc2d4ff146d1492fa9288%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.