Opened 5 years ago
Closed 5 years ago
#32042 closed Cleanup/optimization (fixed)
Incorrect messaging when validate_min/validate_max and min_num == max_num.
| Reported by: | meghanabhange | Owned by: | meghanabhange | 
|---|---|---|---|
| Component: | Forms | Version: | 3.1 | 
| Severity: | Normal | Keywords: | formset, validate_min, validate_max | 
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no | 
| Needs tests: | no | Patch needs improvement: | no | 
| Easy pickings: | no | UI/UX: | no | 
Description
When using Django Formset, the error messaging isn't checking for the condition where both min_num and max_num are equal and both validate_min and validate_max are set to true. 
Code highlighting:
class TestForm(forms.Form): msg = forms.CharField() test_formset = formset_factory( TestForm, min_num=2, max_num=2, validate_min=True, validate_max=True)
When formset is created in the following way and both validate flags are set True the following error messages show up
- If the supplied forms are less than two - 
please submit 2 or more formsexpectedplease submit 2 formssimilarly the reverse is also true when the forms are more than two it gives the error message sayingplease submit 2 or fewer formsexpectedplease submit 2 forms 
This was a  bug reported on Wagtail and after investigating a little I noticed the incorrect messaging was coming from  this part in the validation 
Change History (3)
comment:1 by , 5 years ago
| Has patch: | set | 
|---|---|
| Patch needs improvement: | set | 
| Summary: | Incorrect messaging when both validate_min and validate_max are set true and min_num == max_num. → Incorrect messaging when validate_min/validate_max and min_num == max_num. | 
| Triage Stage: | Unreviewed → Accepted | 
| Type: | Bug → Cleanup/optimization | 
comment:2 by , 5 years ago
| Patch needs improvement: | unset | 
|---|---|
| Triage Stage: | Accepted → Ready for checkin | 
  Note:
 See   TracTickets
 for help on using tickets.
    
Thanks for this ticket. I would change the current messages instead of introducing a new one, e.g.
too_many_forms: "Please submit at most %d forms."too_few_forms: "Please submit at least %d forms."this would be consistent with the current behavior of other min/max validators.
PR