Use empty MultiValueDict for default value of filterset data
sgordon16 opened this issue · 2 comments
Issue Summary
When using the filterset
with Django and passing empty request parameters, the default value for data
is set to an empty dict ({}
) instead of a subclass of MultiValueDict
. This becomes problematic for code that relies on methods specific to MultiValueDict
, such as getlist
.
Reproduction Steps
- Create a Django
filterset
instance. - Send a request with empty parameters.
- Observe that the
data
attribute in thefilterset
is set to an empty dict.
Expected Behavior
The data
attribute in the filterset
should be set to a subclass of MultiValueDict
, even when the request parameters are empty. This ensures that methods like getlist
can be used consistently.
Actual Behavior
The data
attribute is set to a regular empty dict ({}
), causing issues for code that expects a MultiValueDict
instance.
Code Example
# Code snippet that breaks due to the issue
self.filterset.data.getlist("a")
*** AttributeError: 'dict' object has no attribute 'getlist'
Proposed Solution
Consider modifying the default value for data
in the filterset
to ensure it's always a subclass of MultiValueDict
, even when the request parameters are empty.
@sgordon16 Can you open a PR to see what the test suite says?
Fixed in #1634