#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
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):
* stage: Unreviewed => Accepted
* type: Bug => Cleanup/optimization
Comment:
Thank you Jacob for creating this ticket!
My suggestion would be to adjust the docs, since there are `Iterable`
types that I think make less sense to support in this context, for
example, `str` or `dict`. Also, by definition, an `Iterable` only needs to
implement `__iter__`, which means it wouldn't necessarily support
`__next__` (that would make it an `Iterator`). The difference is subtle,
though, and even a `list`, while `Iterable`, is not an `Iterator`.
I'd suggest we update the documentation to clarify that the argument
should be a sequence of model instances, like a list or tuple, rather than
any arbitrary iterable. For example:
{{{
Prefetches the given lookups on a sequence of model instances, such as a
list or tuple.
}}}
This keeps the expectations clear and avoids surprising behavior with edge
cases like passing a string or dictionary.
--
Ticket URL: <https://code.djangoproject.com/ticket/36426#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 view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019730f08347-e3a0c0bb-269e-46aa-bcf0-10068300e474-000000%40eu-central-1.amazonses.com.