Fixed #26743 -- Fixed UnboundLocalError crash when deserializing m2m fields and value isn't iterable.

This commit is contained in:
Baptiste Mispelon 2019-12-11 19:36:57 +01:00 committed by Mariusz Felisiak
parent 3fe5d0128b
commit 738e9e615d
2 changed files with 19 additions and 1 deletions

View file

@ -252,6 +252,20 @@ class JsonSerializerTestCase(SerializersTestBase, TestCase):
for obj in serializers.deserialize('json', test_string, ignore=False):
obj.save()
def test_helpful_error_message_for_many2many_not_iterable(self):
"""
Not iterable many-to-many field value throws a helpful error message.
"""
test_string = """[{
"pk": 1,
"model": "serializers.m2mdata",
"fields": {"data": null}
}]"""
expected = "(serializers.m2mdata:pk=1) field_value was 'None'"
with self.assertRaisesMessage(DeserializationError, expected):
next(serializers.deserialize('json', test_string, ignore=False))
class JsonSerializerTransactionTestCase(SerializersTransactionTestBase, TransactionTestCase):
serializer_name = "json"