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 the filterset 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.
Issue Summary
When using the
filterset
with Django and passing empty request parameters, the default value fordata
is set to an empty dict ({}
) instead of a subclass ofMultiValueDict
. This becomes problematic for code that relies on methods specific toMultiValueDict
, such asgetlist
.Reproduction Steps
filterset
instance.data
attribute in thefilterset
is set to an empty dict.Expected Behavior
The
data
attribute in thefilterset
should be set to a subclass ofMultiValueDict
, even when the request parameters are empty. This ensures that methods likegetlist
can be used consistently.Actual Behavior
The
data
attribute is set to a regular empty dict ({}
), causing issues for code that expects aMultiValueDict
instance.Code Example
Proposed Solution
Consider modifying the default value for
data
in thefilterset
to ensure it's always a subclass ofMultiValueDict
, even when the request parameters are empty.