Fixed #13060 -- Improved error message when ManagementForm data is missing.
This commit is contained in:
parent
f5e07601b2
commit
096b14f0ac
|
@ -90,7 +90,14 @@ class BaseFormSet:
|
||||||
form = ManagementForm(self.data, auto_id=self.auto_id, prefix=self.prefix)
|
form = ManagementForm(self.data, auto_id=self.auto_id, prefix=self.prefix)
|
||||||
if not form.is_valid():
|
if not form.is_valid():
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
_('ManagementForm data is missing or has been tampered with'),
|
_(
|
||||||
|
'ManagementForm data is missing or has been tampered '
|
||||||
|
'with. Missing fields: %(field_names)s'
|
||||||
|
) % {
|
||||||
|
'field_names': ', '.join(
|
||||||
|
form.add_prefix(field_name) for field_name in form.errors
|
||||||
|
),
|
||||||
|
},
|
||||||
code='missing_management_form',
|
code='missing_management_form',
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1301,7 +1301,10 @@ ArticleFormSet = formset_factory(ArticleForm)
|
||||||
|
|
||||||
class TestIsBoundBehavior(SimpleTestCase):
|
class TestIsBoundBehavior(SimpleTestCase):
|
||||||
def test_no_data_raises_validation_error(self):
|
def test_no_data_raises_validation_error(self):
|
||||||
msg = 'ManagementForm data is missing or has been tampered with'
|
msg = (
|
||||||
|
'ManagementForm data is missing or has been tampered with. '
|
||||||
|
'Missing fields: form-TOTAL_FORMS, form-INITIAL_FORMS'
|
||||||
|
)
|
||||||
with self.assertRaisesMessage(ValidationError, msg):
|
with self.assertRaisesMessage(ValidationError, msg):
|
||||||
ArticleFormSet({}).is_valid()
|
ArticleFormSet({}).is_valid()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue