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.
* 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>
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>
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>
* 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>
* status: new => assigned
* owner: nobody => ethurgood
--
Ticket URL: <https://code.djangoproject.com/ticket/20347#comment:5>
* 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>
* owner: ethurgood => David Smith
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/20347#comment:7>
* version: 1.5 => master
Comment:
[https://github.com/django/django/pull/12830 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/20347#comment:8>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/20347#comment:9>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/20347#comment:10>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/20347#comment:11>
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>
* 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>
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>