diff options
| author | David Smith <smithdc@gmail.com> | 2020-04-30 08:34:53 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-06-05 12:01:32 +0200 |
| commit | 433dd737f94b09043f64b873b0ac067b3f97364b (patch) | |
| tree | 5c4dcf3c3c7d36008389d28f72c07f70726d65d0 /django/forms/formsets.py | |
| parent | b5aa9cb20f2d8fbffec3bc18aa31fca5f26d6f64 (diff) | |
Fixed #20347 -- Allowed customizing the maximum number of instantiated forms in formsets.
Co-authored-by: ethurgood <ethurgood@gmail.com>
Diffstat (limited to 'django/forms/formsets.py')
| -rw-r--r-- | django/forms/formsets.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/django/forms/formsets.py b/django/forms/formsets.py index 2b013dcafb..6f819bd696 100644 --- a/django/forms/formsets.py +++ b/django/forms/formsets.py @@ -433,16 +433,21 @@ class BaseFormSet: def formset_factory(form, formset=BaseFormSet, extra=1, can_order=False, can_delete=False, max_num=None, validate_max=False, - min_num=None, validate_min=False): + min_num=None, validate_min=False, absolute_max=None): """Return a FormSet for the given form class.""" if min_num is None: min_num = DEFAULT_MIN_NUM if max_num is None: max_num = DEFAULT_MAX_NUM - # hard limit on forms instantiated, to prevent memory-exhaustion attacks - # limit is simply max_num + DEFAULT_MAX_NUM (which is 2*DEFAULT_MAX_NUM - # if max_num is None in the first place) - absolute_max = max_num + DEFAULT_MAX_NUM + # absolute_max is a hard limit on forms instantiated, to prevent + # memory-exhaustion attacks. Default to max_num + DEFAULT_MAX_NUM + # (which is 2 * DEFAULT_MAX_NUM if max_num is None in the first place). + if absolute_max is None: + absolute_max = max_num + DEFAULT_MAX_NUM + if max_num > absolute_max: + raise ValueError( + "'absolute_max' must be greater or equal to 'max_num'." + ) attrs = { 'form': form, 'extra': extra, |
