diff options
| author | Ian Dash | 2013-03-07 17:29:25 +0000 |
|---|---|---|
| committer | Ian Dash | 2013-03-08 15:08:05 +0000 |
| commit | 66605acaf02d46eb899f495137afb4f9ff127ff0 (patch) | |
| tree | 24d99bece5278d81cd58fb038528907611f30241 /rest_framework/serializers.py | |
| parent | 4e80541824bab0712a816716c5c63ec5623370d8 (diff) | |
| download | django-rest-framework-66605acaf02d46eb899f495137afb4f9ff127ff0.tar.bz2 | |
Errors during deserializing lists now return a list of tuples with
index of bad item in data plus usual errors dict
Diffstat (limited to 'rest_framework/serializers.py')
| -rw-r--r-- | rest_framework/serializers.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index ba9e9e9c..80287522 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -286,8 +286,18 @@ class BaseSerializer(Field): Deserialize primitives -> objects. """ if hasattr(data, '__iter__') and not isinstance(data, (dict, six.text_type)): - # TODO: error data when deserializing lists - return [self.from_native(item, None) for item in data] + object_list = list() + error_list = list() + for count, item in enumerate(data): + obj = self.from_native(item, None) + if self._errors: + error_list.append((count, self._errors)) + object_list.append(obj) + if not error_list: + return object_list + + self._errors = error_list + return None self._errors = {} if data is not None or files is not None: @@ -354,9 +364,6 @@ class BaseSerializer(Field): 'Use the `many=True` flag when instantiating the serializer.', PendingDeprecationWarning, stacklevel=3) - # TODO: error data when deserializing lists - if many: - ret = [self.from_native(item, None) for item in data] ret = self.from_native(data, files) if not self._errors: |
