Skip to content

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

Not hitting the database if no collection is given

George Lubaretsi359212be4451
diff --git a/saleor/product/models/base_products.py b/saleor/product/models/base_products.py
index fba108da9d..8b4af2a680 100644
--- a/saleor/product/models/base_products.py
+++ b/saleor/product/models/base_products.py
@@ -65,8 +65,10 @@ class Product(Subtyped, ItemRange):
return mark_safe(re.sub(r'[-\s]+', '-', value))
def get_products_from_collection(self):
- return Product.objects.filter(collection=self.collection,
- collection__isnull=False).exclude(collection__iexact='')
+ return Product.objects.filter(
+ collection=self.collection,
+ collection__isnull=False
+ ).exclude(collection__iexact='') if self.collection else None
def __iter__(self):
return iter(self.variants.all())