Opened 13 years ago
Closed 13 years ago
#17594 closed Cleanup/optimization (fixed)
Tweak formset to remove extraneous query
Reported by: | Travis Swicegood | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | 1.4-alpha-1 |
Severity: | Normal | Keywords: | modelformset, |
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
A ModelFormset.save
runs a SELECT
due to its reliance on the if not self.get_queryset():
line. Immediately after that call, it loops over self.initial_forms
and returns values set it that. In the instance where get_queryset()
is empty, self.initial_forms
is also empty as far as I can tell.
This patch changes the if not self.get_queryset()
to an if not self.initial_forms
so the extra select is not run. I've added tests that verify the behavior and have run the entire test suite. Everything continues to pass so I believe this is a safe patch to apply, but it definitely needs a second opinion of someone more familiar with model formsets than I.
Attachments (2)
Change History (7)
by , 13 years ago
Attachment: | formset-tweak-109-v1.patch added |
---|
comment:1 by , 13 years ago
comment:2 by , 13 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
Looks fine. However I would place the test in model_formsets_regress (class FormsetTests), where an existing model can also be reused.
comment:3 by , 13 years ago
@claudep: Adjusted. All tests continue to pass and the patch is smaller.
comment:4 by , 13 years ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
Original posting: https://github.com/django/django/pull/109