Skip to content

Commit 8fa867a

Browse files
authored
Fix indentation and implementation of get_initial in ListSerializer
Corrected the get_initial method to return consistent list format and fixed indentation to avoid SyntaxError / IndentationError in tests.
1 parent 7166a78 commit 8fa867a

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

rest_framework/serializers.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -608,14 +608,17 @@ def __init__(self, *args, **kwargs):
608608
super().__init__(*args, **kwargs)
609609
self.child.bind(field_name='', parent=self)
610610

611-
def get_initial(self):
612-
if hasattr(self, 'initial_data'):
613-
# If data is given, we should just return the raw input structure,
614-
# but ensure it's represented in a consistent list format.
615-
if isinstance(self.initial_data, list):
616-
return [self.child.get_initial() for _ in self.initial_data]
611+
def get_initial(self):
612+
"""
613+
Return a list of initial values, one for each item in `initial_data`,
614+
or an empty list if no input data was provided.
615+
"""
616+
if hasattr(self, 'initial_data'):
617+
if isinstance(self.initial_data, list):
618+
return [self.child.get_initial() for _ in self.initial_data]
619+
return []
617620
return []
618-
return []
621+
619622

620623

621624
def get_value(self, dictionary):

0 commit comments

Comments
 (0)