#27001: Regression in query counts using RadioSelect with ModelChoiceField
-------------------------------+--------------------------------------
     Reporter:  AlexHill       |                    Owner:  nobody
         Type:  Uncategorized  |                   Status:  new
    Component:  Forms          |                  Version:  1.10
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Unreviewed
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------

Comment (by AlexHill):

 Created a pull request with a fix.

 `ChoiceFieldRenderer` doesn't have `__iter__` defined, so Python iterates
 over it by calling `__getitem__` with an increasing index until an
 exception is raised. `ChoiceFieldRenderer.__getitem__` calls `list` on
 itself, which turns iteration into an n^2 operation. When the choices are
 backed by a queryset as in ModelChoiceField, that means lots of redundant
 database queries.

 Fixed by adding an `__iter__` method to `ChoiceFieldRenderer` and changing
 `__getitem__` to use it, so that indexing still works.

--
Ticket URL: <https://code.djangoproject.com/ticket/27001#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.649c881843ddf8ad39feb0dd03fd1361%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to