From 096b14f0ac8513c5d76c1b693721b6aede18777d Mon Sep 17 00:00:00 2001 From: manav014 Date: Wed, 21 Oct 2020 04:18:02 +0530 Subject: [PATCH] Fixed #13060 -- Improved error message when ManagementForm data is missing. --- django/forms/formsets.py | 9 ++++++++- tests/forms_tests/tests/test_formsets.py | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/django/forms/formsets.py b/django/forms/formsets.py index 32b3b4ad11..3f57399caf 100644 --- a/django/forms/formsets.py +++ b/django/forms/formsets.py @@ -90,7 +90,14 @@ class BaseFormSet: form = ManagementForm(self.data, auto_id=self.auto_id, prefix=self.prefix) if not form.is_valid(): 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', ) else: diff --git a/tests/forms_tests/tests/test_formsets.py b/tests/forms_tests/tests/test_formsets.py index 267b949461..a11c183f86 100644 --- a/tests/forms_tests/tests/test_formsets.py +++ b/tests/forms_tests/tests/test_formsets.py @@ -1301,7 +1301,10 @@ ArticleFormSet = formset_factory(ArticleForm) class TestIsBoundBehavior(SimpleTestCase): 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): ArticleFormSet({}).is_valid()