Skip to content
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

Use empty MultiValueDict for default value of filterset data #1633

Closed
sgordon16 opened this issue Jan 4, 2024 · 2 comments
Closed

Use empty MultiValueDict for default value of filterset data #1633

sgordon16 opened this issue Jan 4, 2024 · 2 comments

Comments

@sgordon16
Copy link
Contributor

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

  1. Create a Django filterset instance.
  2. Send a request with empty parameters.
  3. 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.

@sgordon16 sgordon16 changed the title Use empty MultiValueDict for default value for data Use empty MultiValueDict for default value of filterset data Jan 4, 2024
@carltongibson
Copy link
Owner

@sgordon16 Can you open a PR to see what the test suite says?

@carltongibson
Copy link
Owner

Fixed in #1634

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants