Skip to content

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

Use proper code for giftcard mutations

Marcin Gębala57d112a02982
diff --git a/saleor/core/utils/promo_code.py b/saleor/core/utils/promo_code.py
index 62b23c5dd9..550b5307ec 100644
--- a/saleor/core/utils/promo_code.py
+++ b/saleor/core/utils/promo_code.py
@@ -17,11 +17,10 @@ class InvalidPromoCode(ValidationError):
class PromoCodeAlreadyExists(ValidationError):
def __init__(self, message=None, **kwargs):
+ code = kwargs.get("code", "promo_code_already_exists")
if message is None:
message = {
- "promo_code": ValidationError(
- "Promo code already exists.", code="promo_code_already_exists"
- )
+ "promo_code": ValidationError("Promo code already exists.", code=code)
}
super().__init__(message, **kwargs)
diff --git a/saleor/graphql/giftcard/mutations.py b/saleor/graphql/giftcard/mutations.py
index 34b5594eb3..2c3f763802 100644
--- a/saleor/graphql/giftcard/mutations.py
+++ b/saleor/graphql/giftcard/mutations.py
@@ -65,7 +65,7 @@ class GiftCardCreate(GiftcardErrorMixin, ModelMutation):
if not code and not instance.pk:
data["code"] = generate_promo_code()
elif not is_available_promo_code(code):
- raise PromoCodeAlreadyExists()
+ raise PromoCodeAlreadyExists(code=GiftcardErrorCode.ALREADY_EXISTS)
cleaned_input = super().clean_input(info, instance, data)
balance = cleaned_input.get("balance", None)
if balance: