Skip to content

Fixed #32511 -- Corrected handling prefetched nested reverse relationships. - #15280

Merged
felixxm merged 1 commit into
django:mainfrom
j4mie:ticket_32511
Jan 5, 2022
Merged

felixxm merged 1 commit into
django:mainfrom
j4mie:ticket_32511

Conversation

@j4mie

@j4mie j4mie commented Jan 4, 2022

Copy link
Copy Markdown
Contributor

https://code.djangoproject.com/ticket/32511

When prefetching a set of child objects related to a set of parent
objects, we usually want to populate the relationship back from the
child to the parent to avoid a query when accessing that relationship
attribute. However, there's an edge case where the child queryset
itself specifies a prefetch back to the parent. In that case, we want
to use the prefetched relationship rather than populating the reverse
relationship from the parent.

@github-actions

github-actions Bot commented Jan 4, 2022

Copy link
Copy Markdown

Hello @j4mie! Thank you for your contribution 💪

As it's your first contribution be sure to check out the patch review checklist.

If you're fixing a ticket from Trac make sure to set the "Has patch" flag and include a link to this PR in the ticket!

If you have any design or process questions then you can ask in the Django forum.

Welcome aboard ⛵️!

@felixxm felixxm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@j4mie Thanks 👍 Looks great 🥇 I left small comments.

Comment thread tests/prefetch_related/tests.py Resolved
Comment thread tests/prefetch_related/tests.py Resolved
Comment thread tests/prefetch_related/tests.py Resolved
Comment thread tests/prefetch_related/tests.py Resolved
Comment thread tests/prefetch_related/tests.py Resolved
@felixxm felixxm changed the title Fixed #32511 -- Correct nested prefetch behaviour Fixed #32511 -- Correcting handling prefetched nested reverse relationships. Jan 5, 2022
@j4mie

j4mie commented Jan 5, 2022

Copy link
Copy Markdown
Contributor Author

Thanks @felixxm, really helpful feedback. I've made the requested changes.

@felixxm felixxm changed the title Fixed #32511 -- Correcting handling prefetched nested reverse relationships. Fixed #32511 -- Corrected handling prefetched nested reverse relationships. Jan 5, 2022
…ships.

When prefetching a set of child objects related to a set of parent
objects, we usually want to populate the relationship back from the
child to the parent to avoid a query when accessing that relationship
attribute. However, there's an edge case where the child queryset
itself specifies a prefetch back to the parent. In that case, we want
to use the prefetched relationship rather than populating the reverse
relationship from the parent.

@felixxm felixxm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@j4mie Thanks for updates 👍 Welcome aboard ⛵

Comment thread tests/prefetch_related/tests.py Resolved
@felixxm
felixxm merged commit f5233dc into django:main Jan 5, 2022
@j4mie
j4mie deleted the ticket_32511 branch January 5, 2022 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants