diff --git a/django_filters/widgets.py b/django_filters/widgets.py index fe99fec9..f5c99b11 100644 --- a/django_filters/widgets.py +++ b/django_filters/widgets.py @@ -205,6 +205,10 @@ def value_from_datadict(self, data, files, name): if value is not None: if value == "": # empty value should parse as an empty list return [] + if isinstance(value, list): + # since django.forms.widgets.SelectMultiple tries to use getlist + # if available, we should return value if it's already an array + return value return value.split(",") return None diff --git a/tests/test_widgets.py b/tests/test_widgets.py index 9e3ba3bf..f50cc1be 100644 --- a/tests/test_widgets.py +++ b/tests/test_widgets.py @@ -383,6 +383,10 @@ class NumberCSVWidget(BaseCSVWidget, NumberInput): result = w.value_from_datadict(data, {}, "price") self.assertEqual(result, ["1", "2"]) + data = {"price": ["1", "2"]} + result = w.value_from_datadict(data, {}, "price") + self.assertEqual(result, ["1", "2"]) + data = {"price": "1,,2"} result = w.value_from_datadict(data, {}, "price") self.assertEqual(result, ["1", "", "2"])