Skip to content

ListSerializer.to_representation cuts data and KeyError is raised if the queryset used has been modified #2727

Closed
@MattBlack85

Description

@MattBlack85

I discovered this problem after upgrading to 3.1, after 86c5fa2 if a QuerySet is passed as iterable data.all() will be called. That's fine until we start to add extra data to the QS and use normal serializers for output.
Case:

objs = Model.objects.filter(x=y)
for obj in objs:
    obj.update(extra_dict)
serializer = MySerializer(objs, many=True)

serializer.data will contain only data from QS, ignoring totally the other portion of data added later and ending with a KeyError because we're missing fields that are declared on serializer, this wasn't happening before since data.all() wasn't called while passing QS around.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions