mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-03 12:00:12 +03:00
Avoid using a mutable as a default parameter
This commit is contained in:
parent
823454da39
commit
1cfd42d46c
|
@ -1623,7 +1623,7 @@ class ListField(Field):
|
|||
List of dicts of native values <- List of dicts of primitive datatypes.
|
||||
"""
|
||||
if html.is_html_input(data):
|
||||
data = html.parse_html_list(data)
|
||||
data = html.parse_html_list(data, default=[])
|
||||
if isinstance(data, type('')) or isinstance(data, collections.Mapping) or not hasattr(data, '__iter__'):
|
||||
self.fail('not_a_list', input_type=type(data).__name__)
|
||||
if not self.allow_empty and len(data) == 0:
|
||||
|
|
|
@ -12,7 +12,7 @@ def is_html_input(dictionary):
|
|||
return hasattr(dictionary, 'getlist')
|
||||
|
||||
|
||||
def parse_html_list(dictionary, prefix='', default=[]):
|
||||
def parse_html_list(dictionary, prefix='', default=None):
|
||||
"""
|
||||
Used to support list values in HTML forms.
|
||||
Supports lists of primitives and/or dictionaries.
|
||||
|
@ -61,7 +61,9 @@ def parse_html_list(dictionary, prefix='', default=[]):
|
|||
ret[index][key] = value
|
||||
else:
|
||||
ret[index] = MultiValueDict({key: [value]})
|
||||
return [ret[item] for item in sorted(ret)] if len(ret.keys()) > 0 else default
|
||||
|
||||
# return the items of the ``ret`` dict, sorted by key, or ``default`` if the dict is empty
|
||||
return [ret[item] for item in sorted(ret)] if ret else default
|
||||
|
||||
|
||||
def parse_html_dict(dictionary, prefix=''):
|
||||
|
|
Loading…
Reference in New Issue
Block a user