{"action":"created","issue":{"url":"https://api.github.com/repos/graphql-python/graphene-django/issues/429","repository_url":"https://api.github.com/repos/graphql-python/graphene-django","labels_url":"https://api.github.com/repos/graphql-python/graphene-django/issues/429/labels{/name}","comments_url":"https://api.github.com/repos/graphql-python/graphene-django/issues/429/comments","events_url":"https://api.github.com/repos/graphql-python/graphene-django/issues/429/events","html_url":"https://github.com/graphql-python/graphene-django/issues/429","id":314880745,"number":429,"title":"DjangoConnectionField.resolve_connection replaces resolved queryset with clone, wiping query cache","user":{"login":"richardpetithory","id":1058924,"avatar_url":"https://avatars1.githubusercontent.com/u/1058924?v=4","gravatar_id":"","url":"https://api.github.com/users/richardpetithory","html_url":"https://github.com/richardpetithory","followers_url":"https://api.github.com/users/richardpetithory/followers","following_url":"https://api.github.com/users/richardpetithory/following{/other_user}","gists_url":"https://api.github.com/users/richardpetithory/gists{/gist_id}","starred_url":"https://api.github.com/users/richardpetithory/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/richardpetithory/subscriptions","organizations_url":"https://api.github.com/users/richardpetithory/orgs","repos_url":"https://api.github.com/users/richardpetithory/repos","events_url":"https://api.github.com/users/richardpetithory/events{/privacy}","received_events_url":"https://api.github.com/users/richardpetithory/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-04-17T02:20:13Z","updated_at":"2018-05-01T13:08:11Z","closed_at":null,"author_association":"NONE","body":"I'm new to graphene-django so please bear with me if my issue is nonsensical.\r\n\r\nI've been spending some time trying to figure out why, when using a resolution method in combination with a `DjangoFilterConnectionField` any prefetches are being unused. I've traced it down to a few things.\r\n\r\nWithin `DjangoFilterConnectionField.merge_querysets` an `&` operator is used to merge two Django `QuerySet`s. The `__and__` method on `QuerySet` creates a new instance of its class, thereby losing any internal caching that may have been accomplished when using `prefetch_related()`. There doesn't seem to be much of a way around this without accessing private attributes of the `QuerySet` object, which is clearly bad practice.\r\n\r\nI then noticed that `DjangoConnectionField.resolve_connection` checks to see `if iterable is not default_manager`. If it's not (which as far as I can tell it never will be if you have a `resolve_things` method on your Query class) it will then follow down the aforementioned path which winds up wiping cache because it creates a new `QuerySet`.\r\n\r\nI wonder, what is the purpose of the following code in `resolve_connection`? If I disable it, the queryset my resolve_things method returns is actually used and thus the prefetch works.\r\n\r\n```\r\n            if iterable is not default_manager:\r\n                default_queryset = maybe_queryset(default_manager)\r\n                iterable = cls.merge_querysets(default_queryset, iterable)\r\n```\r\n\r\nFor reference, my implementation is as follows:\r\n```\r\nclass PostType(DjangoObjectType):\r\n    class Meta:\r\n        model = Post\r\n        filter_fields = ['id', 'title']\r\n        interfaces = (graphene.relay.Node, )\r\n\r\n\r\nclass Query(graphene.ObjectType):\r\n    posts = DjangoFilterConnectionField(PostType)\r\n    \r\n    def resolve_posts(self, info, **kwargs):\r\n        return Post.objects.prefetch_related('customer_posts').all()\r\n```"},"comment":{"url":"https://api.github.com/repos/graphql-python/graphene-django/issues/comments/385666629","html_url":"https://github.com/graphql-python/graphene-django/issues/429#issuecomment-385666629","issue_url":"https://api.github.com/repos/graphql-python/graphene-django/issues/429","id":385666629,"user":{"login":"arianon","id":5781517,"avatar_url":"https://avatars0.githubusercontent.com/u/5781517?v=4","gravatar_id":"","url":"https://api.github.com/users/arianon","html_url":"https://github.com/arianon","followers_url":"https://api.github.com/users/arianon/followers","following_url":"https://api.github.com/users/arianon/following{/other_user}","gists_url":"https://api.github.com/users/arianon/gists{/gist_id}","starred_url":"https://api.github.com/users/arianon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arianon/subscriptions","organizations_url":"https://api.github.com/users/arianon/orgs","repos_url":"https://api.github.com/users/arianon/repos","events_url":"https://api.github.com/users/arianon/events{/privacy}","received_events_url":"https://api.github.com/users/arianon/received_events","type":"User","site_admin":false},"created_at":"2018-05-01T13:08:11Z","updated_at":"2018-05-01T13:08:11Z","author_association":"CONTRIBUTOR","body":"I'm not, I merely [lifted up that logic to a separate method](https://github.com/graphql-python/graphene-django/pull/180/files#diff-4693e93918b75fd2ff08fbe53fec5118L91) to work with Promises.\r\n\r\nI'm no longer familiar with graphene-django so I can't help you here either, apologies and godspeed."}}
{"actor":{"display_login":"arianon"}}