-
Notifications
You must be signed in to change notification settings - Fork 764
Prefetch_related in root resolver not preserved in children resolvers #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It does seem odd that the Do you happen to know if the prefetch query is being made, and then just being ignored? I have seen cases where if the queryset for the child relationship isn't a If you can find that out, it could help narrow down the problem. Also, simple performance operations like this will hopefully be "built-in" soon. See #220 |
qs = Family.objects.prefetch_related('members') should be done in the resolve for members In the FamilyNode
|
What's the progress on this 2 year old issue? it seem to still affect me, as I cannot seem to put prefetch_related on children objects to work at all. @japrogramer @hgylfason Did you get this issue |
@gotexis im adding an attribute to each object in my queryset that is actually the prefetched models. the issue is in the
it seems that resolved is falsed, and that leads to some logic that causes the db to be hit again. Or maybe a shallow copy of the queryset is made somewhere .. not preserving the prefetched attributes. |
I think this line in the django connection resolver that combines the queryset provided |
Is there already any solution for this? |
nope, no solution. big flaw, starting to see some big db hits. |
Sorry for the late reply @gotexis but we never found any solution to this problem. |
@japrogramer @hgylfason @jonbesga I think I've found the issue that is meaning that prefetch_related is not preserved. It's a bug and this PR should fix it: #693 |
@jkimbo I thought that line looked like it was responsible, I didn't tested because i didn't understand the reasoning for merging the querysets. Thanks for the work, hopefully it gets merged soon. |
And thanks @japrogramer for helping figure out the problem. Made fixing it very simple 😄 |
It seems that
prefetch_related
is not preserved in children resolvers. (select_related
is no problem).Example
This example is a simplified version of the code I am working with.
Models
Nodes
"Endpoint"
Query
Problem
The family members were prefetched in the root resolver but that is definitely not used in children resolvers as a db query is made for person data each time a family is resolved.
Question
Does anyone have an idea how to get
prefetch_related
used in children resolvers?The text was updated successfully, but these errors were encountered: