#25279: Make prefetch_related_objects a public API
-------------------------------------+-------------------------------------
Reporter: adamchainz | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by adamchainz):
I've added some tests for the basics (one-to-one/many-to-many traversal
plus `Prefetch` objects) but don't want to go too far basically
duplicating the tests that already exist for `prefetch_related`. The aim
is just to check it accepts the same arguments and thought is put in to
changing it in the future.
I've also changed the function signature to
`prefetch_related_objects(list_of_objects, *lookups)` for the simpler
invocation `prefetch_related_objects(objs, 'lookup1', 'lookup2__and3')`,
as opposed to `prefetch_related_objects(objs, ['lookup1',
'lookup2__and3'])`. This is to defend against the possible bug from
`prefetch_related_objects(objs, 'lookup1')` which would iterate the
characters in `lookup1` leading to errors about attribute `l` etc. not
existing.
I'm guessing that although some existing projects may already be using
`prefetch_related_objects`, it's not Django's policy to worry about
changing the signature of a (previously) private function? Or should I add
type-checking like `if len(args) == 1 and isinstance(args[0], (tuple,
list))` to allow the old style?
--
Ticket URL: <https://code.djangoproject.com/ticket/25279#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 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/068.faedc83aae1aeb5d951f06419f0f8daf%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.