mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #26743 -- Fixed UnboundLocalError crash when deserializing m2m fields and value isn't iterable.
This commit is contained in:
committed by
Mariusz Felisiak
parent
3fe5d0128b
commit
738e9e615d
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user