graphql-python / graphene-django

Build powerful, efficient, and flexible GraphQL APIs with seamless Django integration.
http://docs.graphene-python.org/projects/django/en/latest/
MIT License
4.31k stars 769 forks source link

Issue with nested serializers: expected iterable but did not find one #1102

Open coler-j opened 3 years ago

coler-j commented 3 years ago

Running into similar issue to these issues:

This was supposed to be resolved in https://github.com/graphql-python/graphene-django/pull/395

I am on version2.13.0

I have a nested serialized using many=True for the related serializer, everything saves fine, but on return I am getting:

File "/../graphql/execution/executor.py", line 531, in <lambda>
    lambda resolved: complete_value(
  File "/../graphql/execution/executor.py", line 566, in complete_value
    return complete_list_value(
  File "/../graphql/execution/executor.py", line 603, in complete_list_value
    assert isinstance(result, Iterable), (
AssertionError: User Error: expected iterable, but did not find one for field MyObjectMutationPayload.objects.

This seems to imply there is an issue with the return data.

tcleonard commented 3 years ago

Could you provide an example that makes this problem appear?

KingNonso commented 3 years ago

Here is an example that makes it to appear

class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.User
        fields = "__all__"

class AdminSerializer(serializers.ModelSerializer):
    admin = UserSerializer(many=True)

    class Meta:
        model = models.OrganizationAdmin
        fields = ('admin')

class AdminModelMutation(SerializerMutation):
    class Meta:
        serializer_class = AdminSerializer

ImportError: Could not import 'schema' for Graphene setting 'SCHEMA'. AttributeError: 'NoneType' object has no attribute '_meta'.