#28799: ModelFormSet is incorrectly considered as not valid if initial form is 
not
changed and validate_min=True
---------------------------------+--------------------------------------
     Reporter:  Sergey Fedoseev  |                    Owner:  nobody
         Type:  Bug              |                   Status:  new
    Component:  Forms            |                  Version:  1.11
     Severity:  Normal           |               Resolution:
     Keywords:                   |             Triage Stage:  Unreviewed
    Has patch:  0                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+--------------------------------------

Old description:

> 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.test import TestCase
> from django.forms.models import modelformset_factory
>
> class Price(models.Model):
>     quantity = models.PositiveIntegerField()
>
> class ModelFormsetTest(TestCase):
>     def test_modelformset_validate_min_and_initial(self):
>         data = {
>             'form-TOTAL_FORMS': '2',
>             'form-INITIAL_FORMS': '0',
>             'form-0-quantity': '1',
>         }
>
>         FormSet = modelformset_factory(Price, fields=('quantity',),
> min_num=1, validate_min=True)
>         formset = FormSet(data, initial=[{'quantity': 1}])
>         self.assertTrue(formset.is_valid())
> }}}
>
> Bisected to f5c6295797b8332134fd89e0209a18a1d1d45e0c.

New description:

 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.

--

Comment (by Sergey Fedoseev):

 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.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28799#comment:2>
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/068.299286480fad79a803e0984586ab91b5%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to