Re: [Django] #33835: Select_related().only() in the Prefetch() should automatically add primary keys for reverse relations. (was: Select_related().only() in the Prefetch class increases the number of queries for the InverseManyToOne relation.)

3 views
Skip to first unread message

Django

unread,
Jul 11, 2022, 6:02:25 AM7/11/22
to django-...@googlegroups.com
#33835: Select_related().only() in the Prefetch() should automatically add primary
keys for reverse relations.
-------------------------------------+-------------------------------------
Reporter: Ipakeev | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* cc: Simon Charette (added)
* status: new => closed
* type: Bug => New feature
* resolution: => wontfix


Comment:

Thanks for this proposition, however, `prefetch_related_objects()`
shouldn't implicitly add any columns, this could be unexpected and
misleading. Users who use `only()`/`defer()` are fully responsible for
providing a proper set of columns, see
[https://docs.djangoproject.com/en/stable/ref/models/querysets/#defer a
note in docs]:
> ''"The `defer()` method (and its cousin, `only()`, below) are only for
advanced use-cases. They provide an optimization for when you have
analyzed your queries closely and understand exactly what information you
need and have measured that the difference between returning the fields
you need and the full set of fields for the model will be significant."''

--
Ticket URL: <https://code.djangoproject.com/ticket/33835#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Reply all
Reply to author
Forward
0 new messages