[Django] #20347: Creating a formset with more than max_num forms

28 views
Skip to first unread message

Django

unread,
May 3, 2013, 8:07:19 AM5/3/13
to django-...@googlegroups.com
#20347: Creating a formset with more than max_num forms
-------------------------------+--------------------
Reporter: CarstenF | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 1.5
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
The documentation at
https://docs.djangoproject.com/en/1.5/topics/forms/formsets/#limiting-the-
maximum-number-of-forms seems to indicate (if I understood it correctly)
that the purpose of the `max_num` parameter is to prevent that someone
sends a manipulated, excessively large value in the hidden form field that
states the number of (extra) forms that are submitted, whereas it is not
(directly) related to the number of forms that are //actually// POSTed, or
initialized via parameter `initials`.

However, following the example at that page, with `MyInitials` being a
list of e.g. 1500 initial values and `request.POST` containing more than
1500 formsets:

{{{
#!python
>>> ArticleFormSet = formset_factory(ArticleForm, extra=0)
>>> formset1 = ArticleFormSet(initial=MyInitials)
>>> formset2 = ArticleFormSet(request.POST)
}}}

Now, accessing `formset1.forms[1000]` throws an IndexError exception.

The `max_num` is at its default value of 1000, but in the above context,
it is not expected that `formset1` or `formset2` is reduced to `max_num`
forms -- I'd have expected each to have the full number of forms as
initialized.

Related thread at django-users:
http://thread.gmane.org/gmane.comp.python.django.user/152946

--
Ticket URL: <https://code.djangoproject.com/ticket/20347>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 13, 2013, 7:40:39 AM6/13/13
to django-...@googlegroups.com
#20347: Note that initializing a formset will be limited by max_num
--------------------------------------+------------------------------------
Reporter: CarstenF | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.5
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timo):

* needs_better_patch: => 0
* component: Forms => Documentation
* needs_tests: => 0
* easy: 0 => 1
* needs_docs: => 0
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

I believe the code is working as intended, accepting as a documentation
clarification.

--
Ticket URL: <https://code.djangoproject.com/ticket/20347#comment:1>

Django

unread,
Jun 13, 2013, 8:06:50 AM6/13/13
to django-...@googlegroups.com
#20347: Note that initializing a formset will be limited by max_num
--------------------------------------+------------------------------------
Reporter: CarstenF | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.5
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by anonymous):

Clarifying the documentation would certainly help, but doesn't this mean
that we have to use `max_num=len(MyInitials)` as a "permanent" work-around
in user code?

{{{
#!python
ArticleFormSet = formset_factory(ArticleForm, max_num=len(MyInitials),
extra=0)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20347#comment:2>

Django

unread,
Jun 13, 2013, 8:08:25 AM6/13/13
to django-...@googlegroups.com
#20347: Note that initializing a formset will be limited by max_num
--------------------------------------+------------------------------------
Reporter: CarstenF | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 1.5
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by CarstenF):

(Sorry, the above comment was by me, but I realized too late that I wasn't
logged in when submitting.)

--
Ticket URL: <https://code.djangoproject.com/ticket/20347#comment:3>

Django

unread,
Jun 13, 2013, 10:43:45 AM6/13/13
to django-...@googlegroups.com
#20347: Note that initializing a formset will be limited by max_num
--------------------------+------------------------------------
Reporter: CarstenF | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.5

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------+------------------------------------
Changes (by carljm):

* type: Cleanup/optimization => Bug
* component: Documentation => Forms


Comment:

Yes, this is actually a bug, and it is already fixed in master as part of
the fix for #20084. `absolute_max`, which unlike `max_num` is a hard limit
on the number of forms instantiated, in Django 1.5.1 is set to `max(1000,
max_num)`, which means that if `max_num >= 1000`, then `absolute_max ==
max_num`, meaning `max_num` essentially becomes a hard limit (which it is
not intended or documented to be).

Even with the fix for #20084, where `absolute_max` is set to `max_num +
1000` instead, it would still be possible for someone to hit this issue if
they instantiate a formset with over 1000 more initial forms than
`max_num`. Given that it seems people are using formsets with higher
numbers of forms than anticipated, I think we should probably go further
than #20084 did and fix this fully, by documenting `absolute_max` and
making it explicitly configurable in `formset_factory`.

The other question is whether this deserves a backport to 1.5.X. I think
it probably does, given that it could be a data-loss situation.

--
Ticket URL: <https://code.djangoproject.com/ticket/20347#comment:4>

Django

unread,
Sep 6, 2013, 5:55:51 PM9/6/13
to django-...@googlegroups.com
#20347: Note that initializing a formset will be limited by max_num
--------------------------+-------------------------------------
Reporter: CarstenF | Owner: ethurgood
Type: Bug | Status: assigned
Component: Forms | Version: 1.5

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------+-------------------------------------
Changes (by ethurgood):

* status: new => assigned
* owner: nobody => ethurgood


--
Ticket URL: <https://code.djangoproject.com/ticket/20347#comment:5>

Django

unread,
Sep 18, 2013, 1:23:39 PM9/18/13
to django-...@googlegroups.com
#20347: Add an absolute_max parameter to formset_factory
-----------------------------+-------------------------------------
Reporter: CarstenF | Owner: ethurgood
Type: New feature | Status: assigned
Component: Forms | Version: 1.5

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-----------------------------+-------------------------------------
Changes (by timo):

* needs_better_patch: 0 => 1
* has_patch: 0 => 1
* type: Bug => New feature
* easy: 1 => 0


Comment:

[https://github.com/django/django/pull/1593 Pull request] which has some
minor comments from Carl.

--
Ticket URL: <https://code.djangoproject.com/ticket/20347#comment:6>

Django

unread,
Apr 30, 2020, 5:39:00 PM4/30/20
to django-...@googlegroups.com
#20347: Add an absolute_max parameter to formset_factory
-------------------------------+---------------------------------------
Reporter: Carsten Fuchs | Owner: David Smith

Type: New feature | Status: assigned
Component: Forms | Version: 1.5

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+---------------------------------------
Changes (by David Smith):

* owner: ethurgood => David Smith
* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/20347#comment:7>

Django

unread,
May 1, 2020, 12:03:31 AM5/1/20
to django-...@googlegroups.com
#20347: Add an absolute_max parameter to formset_factory
-------------------------------+---------------------------------------
Reporter: Carsten Fuchs | Owner: David Smith
Type: New feature | Status: assigned
Component: Forms | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+---------------------------------------
Changes (by felixxm):

* version: 1.5 => master


Comment:

[https://github.com/django/django/pull/12830 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/20347#comment:8>

Django

unread,
May 29, 2020, 3:29:49 AM5/29/20
to django-...@googlegroups.com
#20347: Add an absolute_max parameter to formset_factory
-------------------------------+---------------------------------------
Reporter: Carsten Fuchs | Owner: David Smith
Type: New feature | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------+---------------------------------------
Changes (by felixxm):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/20347#comment:9>

Django

unread,
Jun 3, 2020, 3:45:12 PM6/3/20
to django-...@googlegroups.com
#20347: Add an absolute_max parameter to formset_factory
-------------------------------+---------------------------------------
Reporter: Carsten Fuchs | Owner: David Smith
Type: New feature | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+---------------------------------------
Changes (by David Smith):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/20347#comment:10>

Django

unread,
Jun 5, 2020, 6:04:13 AM6/5/20
to django-...@googlegroups.com
#20347: Add an absolute_max parameter to formset_factory
-------------------------------------+-------------------------------------

Reporter: Carsten Fuchs | Owner: David
| Smith
Type: New feature | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/20347#comment:11>

Django

unread,
Jun 5, 2020, 3:04:26 PM6/5/20
to django-...@googlegroups.com
#20347: Add an absolute_max parameter to formset_factory
-------------------------------------+-------------------------------------
Reporter: Carsten Fuchs | Owner: David
| Smith
Type: New feature | Status: assigned
Component: Forms | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"b5aa9cb20f2d8fbffec3bc18aa31fca5f26d6f64" b5aa9cb2]:
{{{
#!CommitTicketReference repository=""
revision="b5aa9cb20f2d8fbffec3bc18aa31fca5f26d6f64"
Refs #20347 -- Added test for formset_factory()'s absolute_max default.

Co-authored-by: ethurgood <ethu...@gmail.com>
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20347#comment:12>

Django

unread,
Jun 5, 2020, 3:04:26 PM6/5/20
to django-...@googlegroups.com
#20347: Add an absolute_max parameter to formset_factory
-------------------------------------+-------------------------------------
Reporter: Carsten Fuchs | Owner: David
| Smith
Type: New feature | Status: closed
Component: Forms | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"433dd737f94b09043f64b873b0ac067b3f97364b" 433dd73]:
{{{
#!CommitTicketReference repository=""
revision="433dd737f94b09043f64b873b0ac067b3f97364b"
Fixed #20347 -- Allowed customizing the maximum number of instantiated
forms in formsets.

Co-authored-by: ethurgood <ethu...@gmail.com>
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20347#comment:13>

Django

unread,
Aug 18, 2020, 3:37:35 AM8/18/20
to django-...@googlegroups.com
#20347: Add an absolute_max parameter to formset_factory
-------------------------------------+-------------------------------------
Reporter: Carsten Fuchs | Owner: David
| Smith
Type: New feature | Status: closed
Component: Forms | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"3254991762b49cfbeb8434842c19bbbad87cd9c6" 3254991]:
{{{
#!CommitTicketReference repository=""
revision="3254991762b49cfbeb8434842c19bbbad87cd9c6"
Refs #20347 -- Allowed customizing the maximum number of instantiated
forms in generic_inlineformset_factory().

Follow up to 433dd737f94b09043f64b873b0ac067b3f97364b.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20347#comment:14>

Reply all
Reply to author
Forward
0 new messages