From 0dc62010b17c79d5b4c0aafdab525af28d71d379 Mon Sep 17 00:00:00 2001 From: Saad Aleem Date: Sat, 27 May 2023 21:27:25 +0500 Subject: [PATCH] Update rest_framework/serializers.py Co-authored-by: Sergei Shishov --- rest_framework/serializers.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 237dbbc70..9db513647 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -610,9 +610,11 @@ class ListSerializer(BaseSerializer): assert self.child is not None, '`child` is a required argument.' assert not inspect.isclass(self.child), '`child` has not been instantiated.' - if kwargs.get('instance', []) and kwargs.get('data', []): - assert len(kwargs.get("data", [])) == len( - kwargs.get("instance", [])), 'Data and instance should have same length' + # instance, data = kwargs.get('instance', []), kwargs.get('data', []) # if you prefer one line assignment support + instance = kwargs.get('instance', []) + data = kwargs.get('data', []) + if instance and data: + assert len(data) == len(instance), 'Data and instance should have same length' super().__init__(*args, **kwargs) self.child.bind(field_name='', parent=self)