mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-02 20:54:42 +03:00
ModelSerializer.restore_object - errors as list
When a ValueError is raised in ModelSerializer.restore_object, the error is set to a one-element list, rather than a bare string.
This commit is contained in:
parent
c52075f392
commit
34c1da3515
|
@ -977,7 +977,7 @@ class ModelSerializer(Serializer):
|
||||||
try:
|
try:
|
||||||
setattr(instance, key, val)
|
setattr(instance, key, val)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
self._errors[key] = self.error_messages['required']
|
self._errors[key] = [self.error_messages['required']]
|
||||||
|
|
||||||
# Any relations that cannot be set until we've
|
# Any relations that cannot be set until we've
|
||||||
# saved the model get hidden away on these
|
# saved the model get hidden away on these
|
||||||
|
|
|
@ -685,7 +685,7 @@ class ModelValidationTests(TestCase):
|
||||||
photo_serializer = PhotoSerializer(instance=photo, data={'album': ''}, partial=True)
|
photo_serializer = PhotoSerializer(instance=photo, data={'album': ''}, partial=True)
|
||||||
self.assertFalse(photo_serializer.is_valid())
|
self.assertFalse(photo_serializer.is_valid())
|
||||||
self.assertTrue('album' in photo_serializer.errors)
|
self.assertTrue('album' in photo_serializer.errors)
|
||||||
self.assertEqual(photo_serializer.errors['album'], photo_serializer.error_messages['required'])
|
self.assertEqual(photo_serializer.errors['album'], [photo_serializer.error_messages['required']])
|
||||||
|
|
||||||
def test_foreign_key_with_partial(self):
|
def test_foreign_key_with_partial(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user