Repository: encode/django-rest-framework

Issue:
List serializer bug with only one object passed
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'
```



Discussion:

Resolving patch:
diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py
--- a/rest_framework/serializers.py
+++ b/rest_framework/serializers.py
@@ -507,7 +507,7 @@ def data(self):
     @property
     def errors(self):
         ret = super(Serializer, self).errors
-        if isinstance(ret, list) and len(ret) == 1 and ret[0].code == 'null':
+        if isinstance(ret, list) and len(ret) == 1 and getattr(ret[0], 'code', None) == 'null':
             # Edge case. Provide a more descriptive error than
             # "this field may not be null", when no data is passed.
             detail = ErrorDetail('No data provided', code='null')
@@ -705,7 +705,7 @@ def data(self):
     @property
     def errors(self):
         ret = super(ListSerializer, self).errors
-        if isinstance(ret, list) and len(ret) == 1 and ret[0].code == 'null':
+        if isinstance(ret, list) and len(ret) == 1 and getattr(ret[0], 'code', None) == 'null':
             # Edge case. Provide a more descriptive error than
             # "this field may not be null", when no data is passed.
             detail = ErrorDetail('No data provided', code='null')


Test patch:
diff --git a/tests/test_serializer.py b/tests/test_serializer.py
--- a/tests/test_serializer.py
+++ b/tests/test_serializer.py
@@ -357,3 +357,16 @@ def test_validation_success(self):
         assert serializer.is_valid()
         assert serializer.validated_data == {'name': '2'}
         assert serializer.errors == {}
+
+
+class Test4606Regression:
+    def setup(self):
+        class ExampleSerializer(serializers.Serializer):
+            name = serializers.CharField(required=True)
+            choices = serializers.CharField(required=True)
+        self.Serializer = ExampleSerializer
+
+    def test_4606_regression(self):
+        serializer = self.Serializer(data=[{"name": "liz"}], many=True)
+        with pytest.raises(serializers.ValidationError):
+            serializer.is_valid(raise_exception=True)