Opened 10 years ago

Last modified 9 years ago

#13060 new Cleanup/optimization

ManagementForm exception in case of bad prefix should be easier to understand

Reported by: Karel Owned by: nobody
Component: Forms Version:
Severity: Normal Keywords: formset, ValidationError, ManagementForm
Cc: shawntherrien@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no


If user adds multiple formsets with prefixes, and specifies the prefix incorrectly when binding the form and validating:

some_formset = SomeFormSet(request.POST, 'articles')

instead of:

some_formset = SomeFormSet(request.POST, prefix='articles') 

Django "suppresses" the original exception and raises only relatively unhelpful "ManagementForm data is missing or has been tampered with".

In file django/forms/, line 57:

  54. if or self.files:
  55.     form = ManagementForm(, auto_id=self.auto_id, prefix=self.prefix)
  56.     if not form.is_valid():
  57.         raise ValidationError('ManagementForm data is missing or has been tampered with') 

Suggestion: include form._errors in output, because for such a small bug in code, it can take a really long time find it.

{'INITIAL_FORMS': [u'This field is required.'],
 'MAX_NUM_FORMS': [u'This field is required.'],
 'TOTAL_FORMS': [u'This field is required.']}

Attachments (1)

formsets.diff (710 bytes) - added by stherrien 10 years ago.
validation error with _errors included

Download all attachments as: .zip

Change History (8)

Changed 10 years ago by stherrien

Attachment: formsets.diff added

validation error with _errors included

comment:1 Changed 10 years ago by anonymous

Cc: shawntherrien@… added
Has patch: set

comment:2 Changed 10 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

Not sure I completely agree with the suggested fix, but yes -- the error on failure of the management form could be a little more helpful, at the very least naming the field that is missing or invalid.

comment:3 Changed 9 years ago by Luke Plant

Type: New feature

comment:4 Changed 9 years ago by Luke Plant

Severity: Normal

comment:5 Changed 9 years ago by Julien Phalip

Needs tests: set
Patch needs improvement: set
Type: New featureCleanup/optimization

Patch would need improvement as per Russell's comment. Also needs tests.

comment:6 Changed 8 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:7 Changed 8 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

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