From 7b9611420267fc87e3f531aa7532c6a75ef948ef Mon Sep 17 00:00:00 2001 From: Paul Craciunoiu Date: Thu, 23 Apr 2020 15:25:36 -0600 Subject: [PATCH 1/3] Don't unwrap lazy user, instead check its class. --- graphene_django/types.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/graphene_django/types.py b/graphene_django/types.py index 0c0cb1cf5..d8979862b 100644 --- a/graphene_django/types.py +++ b/graphene_django/types.py @@ -268,12 +268,9 @@ def resolve_id(self, info): @classmethod def is_type_of(cls, root, info): - if isinstance(root, SimpleLazyObject): - root._setup() - root = root._wrapped if isinstance(root, cls): return True - if not is_valid_django_model(type(root)): + if not is_valid_django_model(type(root.__class__)): raise Exception(('Received incompatible instance "{}".').format(root)) if cls._meta.model._meta.proxy: From c313648096fbdb472695cda76a51f8be3be98ac0 Mon Sep 17 00:00:00 2001 From: Paul Craciunoiu Date: Thu, 23 Apr 2020 15:30:18 -0600 Subject: [PATCH 2/3] Actual fix --- graphene_django/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphene_django/types.py b/graphene_django/types.py index d8979862b..3314f4554 100644 --- a/graphene_django/types.py +++ b/graphene_django/types.py @@ -270,7 +270,7 @@ def resolve_id(self, info): def is_type_of(cls, root, info): if isinstance(root, cls): return True - if not is_valid_django_model(type(root.__class__)): + if not is_valid_django_model(root.__class__): raise Exception(('Received incompatible instance "{}".').format(root)) if cls._meta.model._meta.proxy: From d4041f7acecbc0055ea49333830c8e9bbf09b74c Mon Sep 17 00:00:00 2001 From: Paul Craciunoiu Date: Sat, 9 May 2020 09:40:09 -0600 Subject: [PATCH 3/3] Add test. --- graphene_django/tests/test_query.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/graphene_django/tests/test_query.py b/graphene_django/tests/test_query.py index 698ca2388..bb9cc8840 100644 --- a/graphene_django/tests/test_query.py +++ b/graphene_django/tests/test_query.py @@ -60,6 +60,31 @@ def resolve_reporter(self, info): assert result.data == {"reporter": {"id": "1"}} +def test_should_query_wrapped_simplelazy_objects(): + class ReporterType(DjangoObjectType): + class Meta: + model = Reporter + fields = ("id",) + + class Query(graphene.ObjectType): + reporter = graphene.Field(ReporterType) + + def resolve_reporter(self, info): + return SimpleLazyObject(lambda: SimpleLazyObject(lambda: Reporter(id=1))) + + schema = graphene.Schema(query=Query) + query = """ + query { + reporter { + id + } + } + """ + result = schema.execute(query) + assert not result.errors + assert result.data == {"reporter": {"id": "1"}} + + def test_should_query_well(): class ReporterType(DjangoObjectType): class Meta: