Opened 7 years ago
Last modified 7 years ago
#28799 closed Bug
ModelFormSet is incorrectly considered as not valid if initial form is not changed and validate_min=True — at Version 2
Reported by: | Sergey Fedoseev | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | 1.11 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
I encountered this while trying to migrate from 1.10 to 1.11, ModelFormSet that was valid on 1.10 became invalid on 1.11.
Here's test case:
from django.db import models from django.forms.models import modelformset_factory from django.test import TestCase class Author(models.Model): name = models.CharField(max_length=100) class ModelFormsetTest(TestCase): def test_modelformset_validate_min_and_initial(self): data = { 'form-TOTAL_FORMS': '2', 'form-INITIAL_FORMS': '0', 'form-0-name': 'a', 'form-1-name': 'b', } FormSet = modelformset_factory(Author, min_num=2, exclude=(), validate_min=True) formset = FormSet(data=data, queryset=Author.objects.none(), initial=[{'name': 'a'}]) self.assertTrue(formset.is_valid()) self.assertTrue(len(formset.save()), 2)
Bisected to f5c6295797b8332134fd89e0209a18a1d1d45e0c.
Change History (2)
comment:1 by , 7 years ago
comment:2 by , 7 years ago
Description: | modified (diff) |
---|
I updated test to make it closer to my situation: min_num=2, validate_min=True
, the first form is unchanged, the second one is filled. In this case objects are created.
Note:
See TracTickets
for help on using tickets.
I think the behavior change is desired because if you save that formset (on Django 1.10 and older where it passes validation), no objects will be created since the form didn't change. That behavior seems to conflict with
min_num=1
.