Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Replace generic already_exists code with more specific ones
Aleksander Spyra9b4eb8a1d147
diff --git a/saleor/core/utils/promo_code.py b/saleor/core/utils/promo_code.pyindex a984e35c94..62b23c5dd9 100644--- a/saleor/core/utils/promo_code.py+++ b/saleor/core/utils/promo_code.py@@ -20,7 +20,7 @@ class PromoCodeAlreadyExists(ValidationError):if message is None:message = {"promo_code": ValidationError(- "Promo code already exists.", code="object_already_exists"+ "Promo code already exists.", code="promo_code_already_exists")}super().__init__(message, **kwargs)diff --git a/saleor/graphql/core/utils/error_codes.py b/saleor/graphql/core/utils/error_codes.pyindex e3a77f7964..8a8541db1d 100644--- a/saleor/graphql/core/utils/error_codes.py+++ b/saleor/graphql/core/utils/error_codes.py@@ -56,7 +56,6 @@ class CheckoutErrorCode(Enum):INSUFFICIENT_STOCK = "insufficient_stock"INVALID = "invalid"INVALID_SHIPPING_METHOD = "invalid_shipping_method"- OBJECT_ALREADY_EXISTS = "object_already_exists"OBJECT_DOES_NOT_EXIST = "object_does_not_exist"PAYMENT_ERROR = "payment_error"QUANTITY_GREATER_THAN_LIMIT = "quantity_greater_than_limit"@@ -110,12 +109,14 @@ class ProductErrorCode(Enum):ATTRIBUTE_BAD_VALUE = "attribute_bad_value"ATTRIBUTE_CANNOT_BE_ASSIGNED = "attribute_cannot_be_assigned"ATTRIBUTE_DISABLED_VARIANTS = "attribute_disabled_variants"+ ATTRIBUTE_SLUG_ALREADY_EXISTS = "attribute_slug_already_exists"+ ATTRIBUTE_VALUE_ALREADY_EXISTS = "attribute_value_already_exists"GRAPHQL_ERROR = "graphql_error"INVALID = "invalid"NOT_PRODUCTS_IMAGE = "not_products_image"- OBJECT_ALREADY_EXISTS = "object_already_exists"OBJECT_DOES_NOT_EXIST = "object_does_not_exist"REQUIRED = "required"+ SKU_ALREADY_EXISTS = "sku_already_exists"UNIQUE = "unique"VARIANT_NO_DIGITAL_CONTENT = "variant_no_digital_content"@@ -124,7 +125,7 @@ class ShopErrorCode(Enum):CANNOT_FETCH_TAX_RATES = "cannot_fetch_tax_rates"GRAPHQL_ERROR = "graphql_error"INVALID = "invalid"- OBJECT_ALREADY_EXISTS = "object_already_exists"+ AUTHORIZATION_KEY_ALREADY_EXISTS = "authorization_key_already_exists"OBJECT_DOES_NOT_EXIST = "object_does_not_exist"REQUIRED = "required"UNIQUE = "unique"@@ -134,7 +135,7 @@ class ShippingErrorCode(Enum):GRAPHQL_ERROR = "graphql_error"INVALID = "invalid"MAX_LESS_THAN_MIN = "max_less_than_min"- OBJECT_ALREADY_EXISTS = "object_already_exists"+ DEFAULT_SHIPPING_ZONE_ALREADY_EXISTS = "default_shipping_zone_already_exists"OBJECT_DOES_NOT_EXIST = "object_does_not_exist"REQUIRED = "required"UNIQUE = "unique"@@ -154,8 +155,8 @@ class PaymentErrorCode(Enum):class GiftcardErrorCode(Enum):GRAPHQL_ERROR = "graphql_error"INVALID = "invalid"- OBJECT_ALREADY_EXISTS = "object_already_exists"OBJECT_DOES_NOT_EXIST = "object_does_not_exist"+ PROMO_CODE_ALREADY_EXISTS = "promo_code_already_exists"REQUIRED = "required"UNIQUE = "unique"@@ -164,6 +165,7 @@ class ExtensionsErrorCode(Enum):GRAPHQL_ERROR = "graphql_error"INVALID = "invalid"PLUGIN_MISCONFIGURED = "plugin-misconfigured"+ OBJECT_DOES_NOT_EXIST = "object_does_not_exist"REQUIRED = "required"UNIQUE = "unique"diff --git a/saleor/graphql/product/mutations/attributes.py b/saleor/graphql/product/mutations/attributes.pyindex 138449210c..e72d2c539b 100644--- a/saleor/graphql/product/mutations/attributes.py+++ b/saleor/graphql/product/mutations/attributes.py@@ -120,7 +120,7 @@ class AttributeMixin:raise ValidationError({cls.ATTRIBUTE_VALUES_FIELD: ValidationError(- msg, code=ProductErrorCode.OBJECT_ALREADY_EXISTS+ msg, code=ProductErrorCode.ATTRIBUTE_VALUE_ALREADY_EXISTS)})@@ -184,7 +184,7 @@ class AttributeMixin:{"slug": ValidationError("This attribute's slug already exists.",- code=ProductErrorCode.OBJECT_ALREADY_EXISTS,+ code=ProductErrorCode.ATTRIBUTE_SLUG_ALREADY_EXISTS,)})@@ -543,7 +543,7 @@ def validate_value_is_unique(attribute: models.Attribute, value: models.Attribut{"name": ValidationError(f"Value with slug {value.slug} already exists.",- code=ProductErrorCode.OBJECT_ALREADY_EXISTS,+ code=ProductErrorCode.ATTRIBUTE_SLUG_ALREADY_EXISTS,)})diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.pyindex 0d8f3d24c4..78afe56573 100644--- a/saleor/graphql/product/mutations/products.py+++ b/saleor/graphql/product/mutations/products.py@@ -756,7 +756,7 @@ class ProductCreate(ModelProductMutation):{"sku": ValidationError("Product with this SKU already exists.",- code=ProductErrorCode.OBJECT_ALREADY_EXISTS,+ code=ProductErrorCode.SKU_ALREADY_EXISTS,)})@@ -832,7 +832,7 @@ class ProductUpdate(ProductCreate):{"sku": ValidationError("Product with this SKU already exists.",- code=ProductErrorCode.OBJECT_ALREADY_EXISTS,+ code=ProductErrorCode.SKU_ALREADY_EXISTS,)})diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex b7076e337d..6d5e5f2611 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -690,7 +690,6 @@ enum CheckoutErrorCode {INSUFFICIENT_STOCKINVALIDINVALID_SHIPPING_METHOD- OBJECT_ALREADY_EXISTSOBJECT_DOES_NOT_EXISTPAYMENT_ERRORQUANTITY_GREATER_THAN_LIMIT@@ -1687,8 +1686,8 @@ type GiftcardError {enum GiftcardErrorCode {GRAPHQL_ERRORINVALID- OBJECT_ALREADY_EXISTSOBJECT_DOES_NOT_EXIST+ PROMO_CODE_ALREADY_EXISTSREQUIREDUNIQUE}@@ -2888,12 +2887,14 @@ enum ProductErrorCode {ATTRIBUTE_BAD_VALUEATTRIBUTE_CANNOT_BE_ASSIGNEDATTRIBUTE_DISABLED_VARIANTS+ ATTRIBUTE_SLUG_ALREADY_EXISTS+ ATTRIBUTE_VALUE_ALREADY_EXISTSGRAPHQL_ERRORINVALIDNOT_PRODUCTS_IMAGE- OBJECT_ALREADY_EXISTSOBJECT_DOES_NOT_EXISTREQUIRED+ SKU_ALREADY_EXISTSUNIQUEVARIANT_NO_DIGITAL_CONTENT}@@ -3522,7 +3523,7 @@ enum ShippingErrorCode {GRAPHQL_ERRORINVALIDMAX_LESS_THAN_MIN- OBJECT_ALREADY_EXISTS+ DEFAULT_SHIPPING_ZONE_ALREADY_EXISTSOBJECT_DOES_NOT_EXISTREQUIREDUNIQUE@@ -3692,7 +3693,7 @@ enum ShopErrorCode {CANNOT_FETCH_TAX_RATESGRAPHQL_ERRORINVALID- OBJECT_ALREADY_EXISTS+ AUTHORIZATION_KEY_ALREADY_EXISTSOBJECT_DOES_NOT_EXISTREQUIREDUNIQUEdiff --git a/saleor/graphql/shipping/mutations.py b/saleor/graphql/shipping/mutations.pyindex b8bd7871c8..9851ed05f9 100644--- a/saleor/graphql/shipping/mutations.py+++ b/saleor/graphql/shipping/mutations.py@@ -72,7 +72,7 @@ class ShippingZoneMixin:{"default": ValidationError("Default shipping zone already exists.",- code=ShippingErrorCode.OBJECT_ALREADY_EXISTS,+ code=ShippingErrorCode.DEFAULT_SHIPPING_ZONE_ALREADY_EXISTS,)})diff --git a/saleor/graphql/shop/mutations.py b/saleor/graphql/shop/mutations.pyindex 01126544bd..ab7610e8c4 100644--- a/saleor/graphql/shop/mutations.py+++ b/saleor/graphql/shop/mutations.py@@ -207,7 +207,7 @@ class AuthorizationKeyAdd(BaseShopMutation):{"key_type": ValidationError("Authorization key already exists.",- code=ShopErrorCode.OBJECT_ALREADY_EXISTS,+ code=ShopErrorCode.AUTHORIZATION_KEY_ALREADY_EXISTS,)})diff --git a/tests/api/test_gift_card.py b/tests/api/test_gift_card.pyindex b92680e937..921f17ec82 100644--- a/tests/api/test_gift_card.py+++ b/tests/api/test_gift_card.py@@ -289,7 +289,7 @@ def test_create_gift_card_with_existing_voucher_code(assert errors[0]["field"] == "promoCode"gift_card_errors = content["data"]["giftCardCreate"]["giftCardErrors"]- assert gift_card_errors[0]["code"] == "OBJECT_ALREADY_EXISTS"+ assert gift_card_errors[0]["code"] == "PROMO_CODE_ALREADY_EXISTS"def test_create_gift_card_with_existing_gift_card_code(@@ -307,7 +307,7 @@ def test_create_gift_card_with_existing_gift_card_code(assert errors[0]["field"] == "promoCode"gift_card_errors = content["data"]["giftCardCreate"]["giftCardErrors"]- assert gift_card_errors[0]["code"] == "OBJECT_ALREADY_EXISTS"+ assert gift_card_errors[0]["code"] == "PROMO_CODE_ALREADY_EXISTS"def test_create_gift_card_without_user(staff_api_client, permission_manage_gift_card):