Skip to content

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

Move check for channel existence in 'promotionCreate'. (#15260)

Piotr Zabieglik86b3bd56914f
diff --git a/saleor/graphql/discount/mutations/promotion/promotion_create.py b/saleor/graphql/discount/mutations/promotion/promotion_create.py
index f5db32c2f0..81c6224981 100644
--- a/saleor/graphql/discount/mutations/promotion/promotion_create.py
+++ b/saleor/graphql/discount/mutations/promotion/promotion_create.py
@@ -177,13 +177,13 @@ class PromotionCreate(ModelMutation):
for rule_data in rules_data:
channels = rule_data.pop("channels", None)
rule = models.PromotionRule(promotion=instance, **rule_data)
- rules_with_channels_to_add.append((rule, channels))
+ if channels:
+ rules_with_channels_to_add.append((rule, channels))
rules.append(rule)
models.PromotionRule.objects.bulk_create(rules)
for rule, channels in rules_with_channels_to_add:
- if channels:
- rule.channels.set(channels)
+ rule.channels.set(channels)
return rules