From e05fbcc1b34d31f9569feeacd5d430e08f421f9a Mon Sep 17 00:00:00 2001 From: Daniel Bachler Date: Wed, 11 Oct 2017 15:54:00 +0200 Subject: [PATCH] Fix failing unit test by handling cases where a connection is resolved involving a query with inner join and distinct that is then filtered and would be combined with a filtered queryset that is not distinct. --- graphene_django/fields.py | 4 ++++ graphene_django/tests/test_query.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/graphene_django/fields.py b/graphene_django/fields.py index e755b93..854c691 100644 --- a/graphene_django/fields.py +++ b/graphene_django/fields.py @@ -77,6 +77,10 @@ class DjangoConnectionField(ConnectionField): if isinstance(iterable, QuerySet): if iterable is not default_manager: default_queryset = maybe_queryset(default_manager) + if default_queryset.query.distinct and not iterable.query.distinct: + iterable = iterable.distinct() + elif iterable.query.distinct and not default_queryset.query.distinct: + default_queryset = default_queryset.distinct() iterable = cls.merge_querysets(default_queryset, iterable) _len = iterable.count() else: diff --git a/graphene_django/tests/test_query.py b/graphene_django/tests/test_query.py index 70fae46..913a93f 100644 --- a/graphene_django/tests/test_query.py +++ b/graphene_django/tests/test_query.py @@ -478,7 +478,7 @@ def test_should_query_node_filtering_with_distinct_queryset(): 'films': { 'edges': [{ 'node': { - 'genre': 'ot' + 'genre': 'OT' } }] }