DjangoConnectionField discards select_related
See original GitHub issuegraphene-django==1.3
https://github.com/graphql-python/graphene-django/blob/master/graphene_django/fields.py#L59
When you do this:
# DjangoFilterConnection
@classmethod
def merge_querysets(cls, default_queryset, queryset):
return default_queryset & queryset
you discard any select_related
or prefetch_related
or annotate
that might have been applied to the query set.
When we write a def resolve_things(self,...
method and return a customized QuerySet it is then merged into the default_queryset and this discards everything (I think) except the filtering.
queryset = Deals.objects.select_related('client')
> /usr/local/lib/python2.7/dist-packages/graphene_django/fields.py(58)merge_querysets()
56 return self.model._default_manager
57
---> 58 @classmethod
59 def merge_querysets(cls, default_queryset, queryset):
60 return default_queryset & queryset
ipdb> queryset[0].client
[0.051] SELECT "clients_deal"."id",
"clients_deal"."client_id",
"clients_deal"."agent_id",
"clients_deal"."type",
"clients_deal"."open",
"clients_deal"."stage",
"clients_deal"."created_on",
"clients_deal"."modified_on",
"clients_deal"."client_last_active_on",
"clients_client"."id",
"clients_client"."contact_id",
"clients_client"."email",
"clients_client"."fname",
"clients_client"."lname",
"clients_client"."phone",
"clients_client"."work",
"clients_client"."verified",
"clients_client"."suggested_listings",
"clients_client"."referral_source_id",
"clients_client"."created_on",
"clients_client"."modified_on",
"clients_client"."created_by_id"
FROM "clients_deal"
INNER JOIN "clients_client" ON ("clients_deal"."client_id" = "clients_client"."id")
WHERE ("clients_deal"."agent_id" = 769
AND "clients_deal"."open" = true
AND "clients_deal"."agent_id" = 769)
ORDER BY "clients_deal"."client_last_active_on" DESC
LIMIT 1
# no extra query required
<Client: BOb Hop>
# here is after merging using &
ipdb> merged = default_queryset & queryset
ipdb> merged[0].client
[0.006] SELECT "clients_deal"."id",
"clients_deal"."client_id",
"clients_deal"."agent_id",
"clients_deal"."type",
"clients_deal"."open",
"clients_deal"."stage",
"clients_deal"."created_on",
"clients_deal"."modified_on",
"clients_deal"."client_last_active_on"
FROM "clients_deal"
WHERE ("clients_deal"."agent_id" = 769
AND "clients_deal"."open" = true
AND "clients_deal"."agent_id" = 769)
ORDER BY "clients_deal"."client_last_active_on" DESC
LIMIT 1
[0.006] SELECT "clients_client"."id",
"clients_client"."contact_id",
"clients_client"."email",
"clients_client"."fname",
"clients_client"."lname",
"clients_client"."phone",
"clients_client"."work",
"clients_client"."verified",
"clients_client"."suggested_listings",
"clients_client"."referral_source_id",
"clients_client"."created_on",
"clients_client"."modified_on",
"clients_client"."created_by_id"
FROM "clients_client"
WHERE "clients_client"."id" = 188672
I’m not quite sure what the purpose of merging it with the default query is.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Selecting specific fields using select_related in Django
I want to select only blog name while extracting the article. articles = Articles.objects.all().select_related('blog__name'). The query ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This bug also affects all auto-generated resolvers for ManyToMany fields
Given:
No custom fields or resolve_neighborhoods defined.
The default resolver returns the apt.neighborhoods.all() but then tries to merge it into Apt.objects.all()