Skip to content

List serializer bug with only one object passed #4606

@yelsherbini

Description

@yelsherbini

There is a bug when validating only one object with a list serializer with raise_exception flag set as True.

It worked just fine in 3.4.7.

Steps to reproduce

Here is the class that will cause the issue

class TheSerializer(serializers.Serializer):
    name = serializers.CharField(required=True)
    choices = serializers.CharField(required=True)

Then run

    serializer = TheSerializer(data=[{"name": "hhj"}], many=True)
    serializer.is_valid(raise_exception=True)

Expected behavior

        if self._errors and raise_exception:
>           raise ValidationError(self.errors)
E           rest_framework.exceptions.ValidationError: [{'choices': ['This field is required.']}]

Actual behavior

self = TheSerializer(data=[{'name': 'hhj'}], many=True):
    name = CharField(required=True)
    choices = CharField(required=True)

    @property
    def errors(self):
        ret = super(ListSerializer, self).errors
>       if isinstance(ret, list) and len(ret) == 1 and ret[0].code == 'null':
E       AttributeError: 'dict' object has no attribute 'code'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy