mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-23 14:40:06 +03:00
Raise ValidationError instead of accepting missing value
This commit is contained in:
parent
0bd2f89b8d
commit
47095594de
|
@ -351,8 +351,13 @@ class ManyRelatedMixin(object):
|
|||
except:
|
||||
# Non-form data
|
||||
value = data.get(self.source or field_name)
|
||||
if value == [''] or value is None:
|
||||
value = []
|
||||
else:
|
||||
if value == ['']:
|
||||
value = []
|
||||
|
||||
if value is None and self.required:
|
||||
raise ValidationError("Field '%s' is required" % field_name)
|
||||
|
||||
into[field_name] = [self.from_native(item) for item in value]
|
||||
|
||||
|
||||
|
|
|
@ -340,11 +340,7 @@ class ManyToManyTests(TestCase):
|
|||
"""
|
||||
data = {}
|
||||
serializer = self.serializer_class(data=data)
|
||||
self.assertEqual(serializer.is_valid(), True)
|
||||
instance = serializer.save()
|
||||
self.assertEquals(len(ManyToManyModel.objects.all()), 2)
|
||||
self.assertEquals(instance.pk, 2)
|
||||
self.assertEquals(list(instance.rel.all()), [])
|
||||
self.assertEqual(serializer.is_valid(), False)
|
||||
|
||||
def test_create_empty_relationship_flat_data(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user