Opened 22 months ago

Closed 21 months ago

Last modified 21 months ago

#20872 closed Bug (fixed)

Bad error message if INITIAL_FORMS/TOTAL_FORMS > MAX_NUM_FORMS

Reported by: russellm Owned by: mburst
Component: Forms Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Formset handling currently enforces a MAX_NUM_FORMS check on incoming form data. However, there is no checking or validation that MAX_NUM_FORMS is actually equal to or greater than INITIAL_FORMS/TOTAL_FORMS.

As a result, it's possible to construct and display a formset, but then have that formset fail (with a "list index out of range error") on form submission.

This manifested for me as the following: A model in the admin with inlines; the inline was filled with 2023 inline objects, and the default MAX_NUM_FORMS (1000 was in use. The page takes a long time to load, but it *does* load; when you hit submit, you get the "list index out of range" error as a 500 page, with no suggestion of the underlying problem.

I haven't tested, but AFAICT, the same problem will manifest with a lot less data if you set MAX_NUM_FORMS to a lower value.

Change History (3)

comment:1 Changed 21 months ago by mburst

  • Owner changed from nobody to mburst
  • Status changed from new to assigned

comment:2 Changed 21 months ago by mburst

  • Resolution set to worksforme
  • Status changed from assigned to closed

This has been fixed with commit https://github.com/django/django/commit/f9ab543720532400e8b0d490cdbe67ea09ae9c17. total_form_count can't be larger than absolute_max.

comment:3 Changed 21 months ago by mburst

  • Resolution changed from worksforme to fixed
Note: See TracTickets for help on using tickets.
Back to Top