﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26844	Formset's validate_min doesn't work correctly with empty forms	Wim Feijen	Manasa Patibandla	"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 . "	Bug	closed	Forms	1.9	Normal	fixed			Ready for checkin	1	0	0	0	0	0
