#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: 5.2
(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
-------------------------------------+-------------------------------------
Comment (by Jacob Walls):
Sorry, I didn't realize I left out details: I figured
`next(iter(model_instances)))` would accept iterables simply.
> 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. I'm not
proposing we add a strict type check for model instances: the current
duck-typing approach seems fine.
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/36426#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 visit
https://groups.google.com/d/msgid/django-updates/0107019738834abe-49c9a001-a7c7-4ed1-94bf-9a80a8d9b132-000000%40eu-central-1.amazonses.com.