mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #26743 -- Fixed UnboundLocalError crash when deserializing m2m fields and value isn't iterable.
This commit is contained in:
parent
3fe5d0128b
commit
738e9e615d
2 changed files with 19 additions and 1 deletions
|
@ -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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue