Opened 8 years ago
Closed 8 years ago
#27119 closed Cleanup/optimization (fixed)
full_clean() called too many times during formset validation
Reported by: | Claude Paroz | Owned by: | Karol Sztajerwald |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have a formset with 3 forms in it. I had to debug some stuff with it, but then I realized the full_clean
method is called 21 times when calling the formset.is_valid()
, while I would expect 4 times (once for the formset itself and once for each subform). For example, a validation occurs each time the management_form
property is called. While it may not cause real issues in practice, it's poor design and annoying when trying to debug and follow the validation workflow.
Change History (10)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
I think this affects all sort of formsets. The problem might rather affect the full_clean()
methods of included subforms (notably for the management form).
comment:3 by , 8 years ago
Triage Stage: | Unreviewed → Accepted |
---|
Making BaseFormSet.management_form
a @cached_property
seems to help (not sure if it fully resolves the issue).
comment:4 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 8 years ago
Owner: | changed from | to
---|
comment:7 by , 8 years ago
Needs tests: | set |
---|
comment:9 by , 8 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
I think I'm lacking some details to understand this. Is this for plain formsets and/or model formsets? Are the duplicated calls to
BaseFormSet.full_clean()
and/or some otherfull_clean()
? For example, I added some debugging in Django'stest_basic_formset
but only sawBaseFormSet.full_clean()
called once.