From 296cabe2a59ebe3ca25a53f744cdcdfee6c57e9e Mon Sep 17 00:00:00 2001 From: Shlomo Gordon <38845299+sgordon16@users.noreply.github.com> Date: Fri, 8 Mar 2024 10:15:24 -0500 Subject: [PATCH] Set default value of filterset data to MultiValueDict (#1634) --- django_filters/filterset.py | 3 ++- tests/test_filterset.py | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/django_filters/filterset.py b/django_filters/filterset.py index 1d90db70..779b55bd 100644 --- a/django_filters/filterset.py +++ b/django_filters/filterset.py @@ -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 @@ -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 diff --git a/tests/test_filterset.py b/tests/test_filterset.py index e8da1469..ff30eb18 100644 --- a/tests/test_filterset.py +++ b/tests/test_filterset.py @@ -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 ( @@ -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):