Skip to content

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

Fix code climate's errors (default kwargs == [])

Mateusz Dereniowski2c64c83a5c1a
diff --git a/saleor/product/tasks.py b/saleor/product/tasks.py
index 3df5d17e28..85a5f298d6 100644
--- a/saleor/product/tasks.py
+++ b/saleor/product/tasks.py
@@ -48,7 +48,7 @@ def update_product_minimal_variant_price_task(product_pk):
@app.task
def update_products_minimal_variant_prices_of_catalogues_task(
- product_ids=[], category_ids=[], collection_ids=[]
+ product_ids=None, category_ids=None, collection_ids=None
):
update_products_minimal_variant_prices_of_catalogues(
product_ids, category_ids, collection_ids
diff --git a/saleor/product/utils/variant_prices.py b/saleor/product/utils/variant_prices.py
index bc5179321c..cb420d3f70 100644
--- a/saleor/product/utils/variant_prices.py
+++ b/saleor/product/utils/variant_prices.py
@@ -1,3 +1,6 @@
+import operator
+from functools import reduce
+
from django.db.models.query_utils import Q
from ...discount.utils import fetch_active_discounts
@@ -41,13 +44,28 @@ def update_products_minimal_variant_prices(products, discounts=None):
def update_products_minimal_variant_prices_of_catalogues(
- product_ids=[], category_ids=[], collection_ids=[]
+ product_ids=None, category_ids=None, collection_ids=None
):
- products = Product.objects.filter(
- Q(pk__in=product_ids)
- | Q(category_id__in=category_ids)
- | Q(collectionproduct__collection_id__in=collection_ids)
- ).distinct()
+ # Building the matching products query
+ q_list = []
+ if product_ids:
+ q_list.append(Q(pk__in=product_ids))
+ if category_ids:
+ q_list.append(Q(category_id__in=category_ids))
+ if collection_ids:
+ q_list.append(Q(collectionproduct__collection_id__in=collection_ids))
+ # Asserting that the function was called with some ids
+ if not q_list:
+ raise ValueError(
+ "Provide at least one of the ID lists:\n"
+ "\tproduct_ids,\n"
+ "\tcategory_ids,\n"
+ "\tcollection_ids."
+ )
+ # Querying the products
+ q_or = reduce(operator.or_, q_list)
+ products = Product.objects.filter(q_or).distinct()
+
update_products_minimal_variant_prices(products)