You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 issueself.filterset.data.getlist("a")
***AttributeError: 'dict'objecthasnoattribute'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.
The text was updated successfully, but these errors were encountered:
sgordon16
changed the title
Use empty MultiValueDict for default value for data
Use empty MultiValueDict for default value of filterset data
Jan 4, 2024
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.The text was updated successfully, but these errors were encountered: