mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-27 03:54:01 +03:00
Merge pull request #632 from fernandogrd/master
Fix processing of ManyToManyField when it is empty
This commit is contained in:
commit
2948305b98
|
@ -148,7 +148,7 @@ class ManyRelatedMixin(object):
|
|||
value = data.getlist(self.source or field_name)
|
||||
except:
|
||||
# Non-form data
|
||||
value = data.get(self.source or field_name)
|
||||
value = data.get(self.source or field_name, [])
|
||||
else:
|
||||
if value == ['']:
|
||||
value = []
|
||||
|
|
|
@ -31,3 +31,17 @@ class FieldTests(TestCase):
|
|||
field = serializers.SlugRelatedField(queryset=NullModel.objects.all(), slug_field='pk')
|
||||
self.assertRaises(serializers.ValidationError, field.from_native, '')
|
||||
self.assertRaises(serializers.ValidationError, field.from_native, [])
|
||||
|
||||
|
||||
class TestManyRelateMixin(TestCase):
|
||||
def test_missing_many_to_many_related_field(self):
|
||||
'''
|
||||
Regression test for #632
|
||||
|
||||
https://github.com/tomchristie/django-rest-framework/pull/632
|
||||
'''
|
||||
field = serializers.ManyRelatedField(read_only=False)
|
||||
|
||||
into = {}
|
||||
field.field_from_native({}, None, 'field_name', into)
|
||||
self.assertEqual(into['field_name'], [])
|
||||
|
|
Loading…
Reference in New Issue
Block a user