Skip to content

Issues with Serializers and Querysets #2709

@cancan101

Description

@cancan101

This code:

        serializer = ThingSerializer(data=things, many=True)
        serializer.is_valid(raise_exception=True)
        return Response(serializer.data, status=status.HTTP_200_OK)

yields:

{
    "non_field_errors": [
        "Expected a list of items but got type \"QuerySet\"."
    ]
}

whereas changing the is_valid call to:

        serializer.is_valid(raise_exception=False)

works without a problem. Removing that entire line yields:

When a serializer is passed a data keyword argument you must call .is_valid() before attempting to access the serialized .data representation.
You should either call .is_valid() first, or access .initial_data instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions