Re: include only columns from selected related models in select_related query
Personally, I depend on this behaviour, but it's only because I'm aware of it. Others would be too though, so we can't just make that change (not that you're suggesting that approach). One approach I think could be good would be: Book.objects.select_related('author__hometown').defer("author").get(id=4) Deferring a relation would defer all fields except the key field (which is necessary for lazy loading). What do you think? On Tuesday, 12 February 2019 03:48:00 UTC+11, riccardo.magliocchetti wrote: > > Hello Collin, > > Il 11/02/19 17:35, Collin Anderson ha scritto: > > So would you "defer" the other columns like "only()"? > > Yeah, something like that > > > If nothing else, you could try using .annotate(F('author__hometown')) > (not > > sure if that works) or .values('author__hometown') to just get the > values > > you need. > > Sure but the query would be everything but readable :) > The point of a parameter to select_related would be to avoid to type > explicitly > fields not in select_related and the one in select_related twice. > > > On Mon, Feb 11, 2019 at 5:50 AM Riccardo Magliocchetti < > > riccardo.ma...@gmail.com > wrote: > > > >> Hello, > >> > >> I'm debugging views leaking lots of memory in django 1.11. It looks > like > >> there > >> is some connections with my usage of select_related(). But that's mail > is > >> not > >> about that, not sure about my findings yet :) > >> > >> So I have looked again at the select_related documentation here: > >> > https://docs.djangoproject.com/en/2.1/ref/models/querysets/#select-related > >> > >> and found this: > >> Book.objects.select_related('author__hometown').get(id=4) will cache > the > >> related > >> Person and the related City > >> > >> Up until now i thought that only the related model i've specified would > >> get > >> added to selected columns e.g. only the City because of hometown. But > it > >> looks > >> that's not how it is :) > >> > >> Would it make sense to add a parameter to change select_related > behaviour > >> to > >> include only the columns of the related models specified? That could > save > >> quite > >> a lot of bandwitdh for some use cases. > >> > >> What do you think? > >> > >> Thanks > >> > >> -- > >> Riccardo Magliocchetti > >> @rmistaken > >> > >> http://menodizero.it > >> > >> -- > >> You received this message because you are subscribed to the Google > Groups > >> "Django developers (Contributions to Django itself)" group. > >> To unsubscribe from this group and stop receiving emails from it, send > an > >> email to django-develop...@googlegroups.com . > >> To post to this group, send email to django-d...@googlegroups.com > . > >> Visit this group at https://groups.google.com/group/django-developers. > >> To view this discussion on the web visit > >> > https://groups.google.com/d/msgid/django-developers/a42050d3-25a2-2f47-c841-918d7d085757%40gmail.com > > >> . > >> For more options, visit https://groups.google.com/d/optout. > >> > > > > > -- > Riccardo Magliocchetti > @rmistaken > > http://menodizero.it > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/8db815a1-91a8-4dac-bf60-eeca96a0d71e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: include only columns from selected related models in select_related query
Hello Collin, Il 11/02/19 17:35, Collin Anderson ha scritto: So would you "defer" the other columns like "only()"? Yeah, something like that If nothing else, you could try using .annotate(F('author__hometown')) (not sure if that works) or .values('author__hometown') to just get the values you need. Sure but the query would be everything but readable :) The point of a parameter to select_related would be to avoid to type explicitly fields not in select_related and the one in select_related twice. On Mon, Feb 11, 2019 at 5:50 AM Riccardo Magliocchetti < riccardo.magliocche...@gmail.com> wrote: Hello, I'm debugging views leaking lots of memory in django 1.11. It looks like there is some connections with my usage of select_related(). But that's mail is not about that, not sure about my findings yet :) So I have looked again at the select_related documentation here: https://docs.djangoproject.com/en/2.1/ref/models/querysets/#select-related and found this: Book.objects.select_related('author__hometown').get(id=4) will cache the related Person and the related City Up until now i thought that only the related model i've specified would get added to selected columns e.g. only the City because of hometown. But it looks that's not how it is :) Would it make sense to add a parameter to change select_related behaviour to include only the columns of the related models specified? That could save quite a lot of bandwitdh for some use cases. What do you think? Thanks -- Riccardo Magliocchetti @rmistaken http://menodizero.it -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/a42050d3-25a2-2f47-c841-918d7d085757%40gmail.com . For more options, visit https://groups.google.com/d/optout. -- Riccardo Magliocchetti @rmistaken http://menodizero.it -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/a4755ef5-26af-ffee-a7c1-4c12f0f850e6%40gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: include only columns from selected related models in select_related query
So would you "defer" the other columns like "only()"? If nothing else, you could try using .annotate(F('author__hometown')) (not sure if that works) or .values('author__hometown') to just get the values you need. On Mon, Feb 11, 2019 at 5:50 AM Riccardo Magliocchetti < riccardo.magliocche...@gmail.com> wrote: > Hello, > > I'm debugging views leaking lots of memory in django 1.11. It looks like > there > is some connections with my usage of select_related(). But that's mail is > not > about that, not sure about my findings yet :) > > So I have looked again at the select_related documentation here: > https://docs.djangoproject.com/en/2.1/ref/models/querysets/#select-related > > and found this: > Book.objects.select_related('author__hometown').get(id=4) will cache the > related > Person and the related City > > Up until now i thought that only the related model i've specified would > get > added to selected columns e.g. only the City because of hometown. But it > looks > that's not how it is :) > > Would it make sense to add a parameter to change select_related behaviour > to > include only the columns of the related models specified? That could save > quite > a lot of bandwitdh for some use cases. > > What do you think? > > Thanks > > -- > Riccardo Magliocchetti > @rmistaken > > http://menodizero.it > > -- > You received this message because you are subscribed to the Google Groups > "Django developers (Contributions to Django itself)" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-developers+unsubscr...@googlegroups.com. > To post to this group, send email to django-developers@googlegroups.com. > Visit this group at https://groups.google.com/group/django-developers. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-developers/a42050d3-25a2-2f47-c841-918d7d085757%40gmail.com > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAFO84S5M8o1ONpfm%3D27ofFRcYCeU%2B-pGxNmTbm7q1kKC6Mk64w%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.