-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Fix ListSerializer.get_initial to return consistent initial list structure #9822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7166a78
8fa867a
3e19d6a
dc1e9d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -597,7 +597,7 @@ class ListSerializer(BaseSerializer): | |||
| 'max_length': _('Ensure this field has no more than {max_length} elements.'), | ||||
| 'min_length': _('Ensure this field has at least {min_length} elements.') | ||||
| } | ||||
|
|
||||
| def __init__(self, *args, **kwargs): | ||||
| self.child = kwargs.pop('child', copy.deepcopy(self.child)) | ||||
| self.allow_empty = kwargs.pop('allow_empty', True) | ||||
|
|
@@ -609,10 +609,16 @@ def __init__(self, *args, **kwargs): | |||
| self.child.bind(field_name='', parent=self) | ||||
|
|
||||
| def get_initial(self): | ||||
| """ | ||||
| Return a list of initial values, one for each item in `initial_data`, | ||||
| or an empty list if no input data was provided. | ||||
| """ | ||||
| if hasattr(self, 'initial_data'): | ||||
| return self.to_representation(self.initial_data) | ||||
| if isinstance(self.initial_data, list): | ||||
| return [self.child.get_initial() for _ in self.initial_data] | ||||
| return [] | ||||
|
||||
| return [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not seem correct, as all the list items would be the same.