Opened 7 years ago

Last modified 6 years ago

#28799 closed Bug

ModelFormSet is incorrectly considered as not valid if initial form is not changed and validate_min=True — at Initial Version

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

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.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top