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

List serializer bug with only one object passed #4606

yelsherbini opened this issue Oct 21, 2016 · 0 comments

List serializer bug with only one object passed #4606

yelsherbini opened this issue Oct 21, 2016 · 0 comments


Copy link

yelsherbini commented Oct 21, 2016

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)

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)

    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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants