#10156 closed (fixed)
ModelMultipleChoiceField does O(n) queries where O(1) will suffice
Reported by: | Alex Gaynor | Owned by: | Alex Gaynor |
---|---|---|---|
Component: | Forms | Version: | 1.0 |
Severity: | 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
Which is hugely inefficient, selecting 20 items already means you're going outside the reasonable limits for SQL queries.
Attachments (2)
Change History (13)
by , 16 years ago
Attachment: | multiple-model-choice-field.diff added |
---|
comment:1 by , 16 years ago
comment:2 by , 16 years ago
Status: | new → assigned |
---|---|
Triage Stage: | Unreviewed → Accepted |
by , 16 years ago
Attachment: | multiple-model-choice-field.2.diff added |
---|
comment:3 by , 16 years ago
milestone: | → 1.1 |
---|
comment:4 by , 16 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:5 by , 16 years ago
Triage Stage: | Ready for checkin → Accepted |
---|
This isn't quite correct yet. In the patched version, self.queryset.filter(pk=pk)
will never raise the ValueError
the try/except block is catching against, so the logic is incorrect somewhere.
comment:6 by , 16 years ago
Patch needs improvement: | set |
---|
comment:7 by , 16 years ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
Jacob's complaint was not accurate as the tests found here:
http://code.djangoproject.com/browser/django/trunk/tests/modeltests/model_forms/models.py#L827
Still pass, and they obviously rely on that ValueError logic being correct(the reason this works is get_db_prep_lookup is called on the object being added to the QuerySet, not on the Query being executed).
comment:8 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
comment:9 by , 15 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
r10482 uses filter which doesn't return same order as pks given, where as previous implementation appended values to the end. e.g.: clean([3,2]) -> {object 3, object 2} where as new implementation returns {object 2, object 3}
Its a changed in the behavior, which I was using ...
comment:10 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
This ticket was fixed, if you believe there is a new issue please file a new ticket.
Had to develop similar solution (and custom widget) to get rid of mentioned issue.