Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not access the internals of SimpleLazyObject #945

Merged
merged 3 commits into from
May 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions graphene_django/tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions graphene_django/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(root.__class__):
raise Exception(('Received incompatible instance "{}".').format(root))

if cls._meta.model._meta.proxy:
Expand Down