Skip to content

Commit

Permalink
Set default value of filterset data to MultiValueDict (#1634)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgordon16 authored Mar 8, 2024
1 parent 1808e21 commit 296cabe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion django_filters/filterset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.db import models
from django.db.models.constants import LOOKUP_SEP
from django.db.models.fields.related import ManyToManyRel, ManyToOneRel, OneToOneRel
from django.utils.datastructures import MultiValueDict

from .conf import settings
from .constants import ALL_FIELDS
Expand Down Expand Up @@ -176,7 +177,7 @@ def __init__(self, data=None, queryset=None, *, request=None, prefix=None):
model = queryset.model

self.is_bound = data is not None
self.data = data or {}
self.data = data or MultiValueDict()
self.queryset = queryset
self.request = request
self.form_prefix = prefix
Expand Down
5 changes: 5 additions & 0 deletions tests/test_filterset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from django.db import models
from django.test import TestCase, override_settings
from django.utils.datastructures import MultiValueDict

from django_filters.exceptions import FieldLookupError
from django_filters.filters import (
Expand Down Expand Up @@ -745,6 +746,10 @@ def test_creating_with_request(self):
m = mock.Mock()
f = self.F(request=m)
self.assertEqual(f.request, m)

def test_creating_with_no_data_default(self):
f = self.F()
self.assertIsInstance(f.data, MultiValueDict)


class FilterSetQuerysetTests(TestCase):
Expand Down

0 comments on commit 296cabe

Please sign in to comment.