Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Fix filter data with 0 value is not working issue (#10987)

Aswinkumar R436f52ee3d0c
diff --git a/saleor/graphql/core/tests/test_core.py b/saleor/graphql/core/tests/test_core.py
index d32f2abe2d..044d4b184b 100644
--- a/saleor/graphql/core/tests/test_core.py
+++ b/saleor/graphql/core/tests/test_core.py
@@ -446,6 +446,18 @@ def test_filter_range_field(value, count, product_indexes, product_list):
assert list(result) == expected_products
+def test_filter_products_with_zero_discount(product_list):
+ product_list[0].channel_listings.update(discounted_price_amount=0)
+ qs = ProductChannelListing.objects.all().order_by("pk")
+ field = "discounted_price_amount"
+
+ result = filter_range_field(qs, field, {"lte": 0, "gte": 0})
+
+ expected_products = list(qs.filter(product=product_list[0]))
+ assert result.count() == 1
+ assert list(result) == expected_products
+
+
def test_get_duplicated_values():
values = ("a", "b", "a", 1, 1, 1, 2)
diff --git a/saleor/graphql/utils/filters.py b/saleor/graphql/utils/filters.py
index e938d8de47..c0a09a092f 100644
--- a/saleor/graphql/utils/filters.py
+++ b/saleor/graphql/utils/filters.py
@@ -21,10 +21,10 @@ def filter_by_period(queryset, period, field_name):
def filter_range_field(qs, field, value):
gte, lte = value.get("gte"), value.get("lte")
- if gte:
+ if gte is not None:
lookup = {f"{field}__gte": gte}
qs = qs.filter(**lookup)
- if lte:
+ if lte is not None:
lookup = {f"{field}__lte": lte}
qs = qs.filter(**lookup)
return qs