Skip to content

Commit 2225ed6

Browse files
authored
Do not access the internals of SimpleLazyObject (#945)
1 parent ed4937f commit 2225ed6

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

graphene_django/tests/test_query.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,31 @@ def resolve_reporter(self, info):
6060
assert result.data == {"reporter": {"id": "1"}}
6161

6262

63+
def test_should_query_wrapped_simplelazy_objects():
64+
class ReporterType(DjangoObjectType):
65+
class Meta:
66+
model = Reporter
67+
fields = ("id",)
68+
69+
class Query(graphene.ObjectType):
70+
reporter = graphene.Field(ReporterType)
71+
72+
def resolve_reporter(self, info):
73+
return SimpleLazyObject(lambda: SimpleLazyObject(lambda: Reporter(id=1)))
74+
75+
schema = graphene.Schema(query=Query)
76+
query = """
77+
query {
78+
reporter {
79+
id
80+
}
81+
}
82+
"""
83+
result = schema.execute(query)
84+
assert not result.errors
85+
assert result.data == {"reporter": {"id": "1"}}
86+
87+
6388
def test_should_query_well():
6489
class ReporterType(DjangoObjectType):
6590
class Meta:

graphene_django/types.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,9 @@ def resolve_id(self, info):
272272

273273
@classmethod
274274
def is_type_of(cls, root, info):
275-
if isinstance(root, SimpleLazyObject):
276-
root._setup()
277-
root = root._wrapped
278275
if isinstance(root, cls):
279276
return True
280-
if not is_valid_django_model(type(root)):
277+
if not is_valid_django_model(root.__class__):
281278
raise Exception(('Received incompatible instance "{}".').format(root))
282279

283280
if cls._meta.model._meta.proxy:

0 commit comments

Comments
 (0)