#36426: prefetch_related_objects() is doc'd to accept iterables but only accepts
sequences
-------------------------------------+-------------------------------------
     Reporter:  Jacob Walls          |                    Owner:  Luna
         Type:                       |                   Status:  assigned
  Cleanup/optimization               |
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

 * version:  5.2 => dev

Comment:

 Replying to [comment:4 Jacob Walls]:
 > Sorry, I didn't realize I left out details: I figured
 `next(iter(model_instances)))` would accept iterables simply.

 Makes sense :-)

 > > This keeps the expectations clear and avoids surprising behavior with
 edge cases like passing a string or dictionary.
 >
 > Certainly a string makes no sense, but a string is both an iterable and
 a sequence, so it's the same no matter what we choose here.

 Good point.

 > I'm not proposing we add a strict type check for model instances: the
 current duck-typing approach seems fine.

 I agree.

 > I used `set` in the bug report, but where I encountered this in practice
 was with a `dict_values`. I could have just as easily ended up trying
 `dict` or `dict_keys`. I guess expected them all to just work.

 Your points make sense and I think changing the code (with tests) to
 replace `first_obj = obj_list[0]` with `next(iter(obj_list))` makes the
 code more robust, and as you say, it aligns with the docs.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36426#comment:7>
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 visit 
https://groups.google.com/d/msgid/django-updates/010701977f03fe94-0757e0cb-5bad-4f1c-a2dd-605de71ca79b-000000%40eu-central-1.amazonses.com.

Reply via email to