Skip to content

DjangoConnectionField discards select_related #179

Closed
@crucialfelix

Description

@crucialfelix

graphene-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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions