#31295: required ModelChoiceField makes duplicate (cursor) queries to the
database
-------------------------------------+-------------------------------------
Reporter: Aurélien Pardon | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Forms | Version: 2.2
Severity: Normal | Resolution: needsinfo
Keywords: Model | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):
* status: new => closed
* type: Bug => Cleanup/optimization
* resolution: => needsinfo
Comment:
Hi Aurélien,
Thanks for the follow-up. Really not a problem. Better to ''measure twice,
cut once'' and all that. :)
The iterator behaviour — refetching each time — was deliberate, and is
correct. I can't see an adjustment there that doesn't entail a fix to
#22841.
(Duplicate then...)
''Maybe you don't want that behaviour and a ModelChoiceIterator subclass
would work for you?'' But as soon as I think that, better would be a
Select widget subclass.
#27370 fixed the `Select.use_required_attribute()` behaviour. It
necessarily needs the first item for the `_choice_has_empty_value` check.
So, give the design of ModelChoiceIterator, fetching it isn't a Bug. (Yes
there's an extra query but correctness trumps performance.)
''Maybe'' there's a way of performing that
`Select.use_required_attribute()` check without fetching the first
item...? Would that be better than using a subclass for this kind of case?
(If I know my dataset I can just return `False` from
`use_required_attribute()`.)
I guess we could look at a patch there. I'm going to call this needsinfo
pending such though. I hope that makes sense.
--
Ticket URL: <https://code.djangoproject.com/ticket/31295#comment:4>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.fc9bd1ea75724bc0a976c6c561e6976c%40djangoproject.com.