Skip to content
/ django Public

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

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

Fixed #32511 -- Corrected handling prefetched nested reverse relationships.#15280
felixxm merged 1 commit intodjango:mainfrom
j4mie:ticket_32511

Conversation

@j4mie
Copy link
Contributor

@j4mie j4mie commented Jan 4, 2022

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
Copy link

github-actions bot commented Jan 4, 2022

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 ⛵️!

Copy link
Member

@felixxm felixxm left a comment

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.

@felixxm felixxm changed the title Fixed #32511 -- Correct nested prefetch behaviour Fixed #32511 -- Correcting handling prefetched nested reverse relationships. Jan 5, 2022
@j4mie
Copy link
Contributor Author

j4mie commented Jan 5, 2022

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.
Copy link
Member

@felixxm felixxm left a comment

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 ⛵

@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