Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Unify sth-already-exists codes
Aleksander Spyra8323acee3530
diff --git a/saleor/core/utils/promo_code.py b/saleor/core/utils/promo_code.pyindex 044893c36c..0787855b0d 100644--- a/saleor/core/utils/promo_code.py+++ b/saleor/core/utils/promo_code.py@@ -4,7 +4,7 @@ from django.core.exceptions import ValidationErrorfrom ...discount.models import Voucherfrom ...giftcard.models import GiftCard-from ...graphql.core.utils.error_codes import CheckoutErrorCode+from ...graphql.core.utils.error_codes import CheckoutErrorCode, CommonErrorCodeclass InvalidPromoCode(ValidationError):@@ -24,7 +24,7 @@ class PromoCodeAlreadyExists(ValidationError):message = {"promo_code": ValidationError("Promo code already exists.",- code=CheckoutErrorCode.PROMO_CODE_ALREADY_EXISTS,+ code=CommonErrorCode.OBJECT_ALREADY_EXISTS,)}super().__init__(message, **kwargs)diff --git a/saleor/graphql/core/utils/error_codes.py b/saleor/graphql/core/utils/error_codes.pyindex 03fb35c439..07dc1fd5f3 100644--- a/saleor/graphql/core/utils/error_codes.py+++ b/saleor/graphql/core/utils/error_codes.py@@ -62,7 +62,6 @@ class CheckoutErrorCode(Enum):INSUFFICIENT_STOCK = "insufficient_stock"INVALID_PROMO_CODE = "invalid_promo_code"INVALID_SHIPPING_METHOD = "invalid_shipping_method"- PROMO_CODE_ALREADY_EXISTS = "promo_code_already_exists"QUANTITY_GREATER_THAN_LIMIT = "quantity_greater_than_limit"SHIPPING_ADDRESS_NOT_SET = "shipping_address_not_set"SHIPPING_METHOD_NOT_APPLICABLE = "shipping_method_not_applicable"@@ -99,7 +98,6 @@ class OrderErrorCode(Enum):class CommonErrorCode(Enum):- AUTHORIZATION_KEY_ALREADY_EXISTS = "authorization_key_already_exists"CANNOT_FETCH_TAX_RATES = "cannot_fetch_tax_rates"DOES_NOT_EXIST = "does_not_exist"GRAPHQL_ERROR = "graphql_error"@@ -109,6 +107,7 @@ class CommonErrorCode(Enum):INVALID_WEIGHT_UNIT = "invalid_weight_unit"MISSING_VALUE = "missing_value"NON_BLANK_VALUE_REQUIRED = "non_blank_value_required"+ OBJECT_ALREADY_EXISTS = "object_already_exists"PARTIAL_PAYMENT_NOT_ALLOWED = "partial_payment_not_allowed"PAYMENT_ERROR = "payment_error"POSITIVE_NUMBER_REQUIRED = "positive_number_required"@@ -118,12 +117,10 @@ class CommonErrorCode(Enum):class AttributeErrorCode(Enum):ATTRIBUTE_ALREADY_ASSIGNED = "attribute_already_assigned"- ATTRIBUTE_ALREADY_EXISTS = "attribute_already_exists"ATTRIBUTE_BAD_VALUE = "attribute_bad_value"ATTRIBUTE_CANNOT_BE_ASSIGNED = "attribute_cannot_be_assigned"ATTRIBUTE_DISABLED_VARIANTS = "attribute_disabled_variants"ATTRIBUTE_NON_ASSIGNABLE = "attribute_non_assignable"- ATTRIBUTE_SLUG_ALREADY_EXISTS = "attribute_slug_already_exists"ATTRIBUTE_SLUG_BLANK = "attribute_slug_blank"ATTRIBUTE_VALUES_NOT_UNIQUE = "attribute_values_not_unique"@@ -135,11 +132,9 @@ class DigitalContentErrorCode(Enum):class ProductErrorCode(Enum):NOT_PRODUCTS_IMAGE = "not_products_image"- PRODUCT_ALREADY_EXISTS = "product_already_exists"class ShippingErrorCode(Enum):- DEFAULT_SHIPPING_ZONE_ALREADY_EXISTS = "default_shipping_zone_already_exists"MAX_LESS_THAN_MIN = "max_less_than_min"diff --git a/saleor/graphql/product/mutations/attributes.py b/saleor/graphql/product/mutations/attributes.pyindex 4e7c7602e8..cdbc8ef85b 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=AttributeErrorCode.ATTRIBUTE_ALREADY_EXISTS+ msg, code=CommonErrorCode.OBJECT_ALREADY_EXISTS)})@@ -186,7 +186,7 @@ class AttributeMixin:{"slug": ValidationError("This attribute's slug already exists.",- code=AttributeErrorCode.ATTRIBUTE_SLUG_ALREADY_EXISTS,+ code=CommonErrorCode.OBJECT_ALREADY_EXISTS,)})@@ -545,7 +545,7 @@ def validate_value_is_unique(attribute: models.Attribute, value: models.Attribut{"name": ValidationError(f"Value with slug {value.slug} already exists.",- code=AttributeErrorCode.ATTRIBUTE_SLUG_ALREADY_EXISTS,+ code=CommonErrorCode.OBJECT_ALREADY_EXISTS,)})diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.pyindex 1b8b5cd604..dc3b293e53 100644--- a/saleor/graphql/product/mutations/products.py+++ b/saleor/graphql/product/mutations/products.py@@ -756,7 +756,7 @@ class ProductCreate(ModelMutation):{"sku": ValidationError("Product with this SKU already exists.",- code=ProductErrorCode.PRODUCT_ALREADY_EXISTS,+ code=CommonErrorCode.OBJECT_ALREADY_EXISTS,)})@@ -832,7 +832,7 @@ class ProductUpdate(ProductCreate):{"sku": ValidationError("Product with this SKU already exists.",- code=ProductErrorCode.PRODUCT_ALREADY_EXISTS,+ code=CommonErrorCode.OBJECT_ALREADY_EXISTS,)})diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 953f531160..ebf8cb255e 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -143,8 +143,8 @@ type AssignNavigation {type Attribute implements Node {id: ID!- productTypes(before: String, after: String, first: Int, last: Int): ProductTypeCountableConnection- productVariantTypes(before: String, after: String, first: Int, last: Int): ProductTypeCountableConnection+ productTypes(before: String, after: String, first: Int, last: Int): ProductTypeCountableConnection!+ productVariantTypes(before: String, after: String, first: Int, last: Int): ProductTypeCountableConnection!privateMeta: [MetaStore]!meta: [MetaStore]!inputType: AttributeInputTypeEnum@@ -971,7 +971,6 @@ enum CountryCode {LTLUMO- MKMGMWMY@@ -1005,6 +1004,7 @@ enum CountryCode {NUNFKP+ MKMPNOOM@@ -1390,15 +1390,12 @@ enum ErrorCode {ACTIVATE_SUPERUSER_ACCOUNTASSIGN_MENU_ITEM_TO_ITSELFATTRIBUTE_ALREADY_ASSIGNED- ATTRIBUTE_ALREADY_EXISTSATTRIBUTE_BAD_VALUEATTRIBUTE_CANNOT_BE_ASSIGNEDATTRIBUTE_DISABLED_VARIANTSATTRIBUTE_NON_ASSIGNABLE- ATTRIBUTE_SLUG_ALREADY_EXISTSATTRIBUTE_SLUG_BLANKATTRIBUTE_VALUES_NOT_UNIQUE- AUTHORIZATION_KEY_ALREADY_EXISTSBILLING_ADDRESS_NOT_SETBLANKCANNOT_ASSIGN_NODE@@ -1410,7 +1407,6 @@ enum ErrorCode {CONTRADICTIONDEACTIVATE_OWN_ACCOUNTDEACTIVATE_SUPERUSER_ACCOUNT- DEFAULT_SHIPPING_ZONE_ALREADY_EXISTSDELETE_LINE_NON_DRAFT_ORDERDELETE_NON_DRAFT_ORDERDELETE_NON_STAFF_USER@@ -1461,6 +1457,7 @@ enum ErrorCode {NOT_USERS_ADDRESSNULLNULL_CHARACTERS_NOT_ALLOWED+ OBJECT_ALREADY_EXISTSORDER_INVALID_SHIPPING_METHODORDER_NO_PAYMENTORDER_NO_SHIPPING_ADDRESS@@ -1473,8 +1470,6 @@ enum ErrorCode {PASSWORD_TOO_SIMILARPAYMENT_ERRORPOSITIVE_NUMBER_REQUIRED- PRODUCT_ALREADY_EXISTS- PROMO_CODE_ALREADY_EXISTSQUANTITY_GREATER_THAN_LIMITQUANTITY_LESS_THAN_ONEREFUND_MANUAL_PAYMENTdiff --git a/saleor/graphql/shipping/mutations.py b/saleor/graphql/shipping/mutations.pyindex 08d341491e..f14afab9d3 100644--- a/saleor/graphql/shipping/mutations.py+++ b/saleor/graphql/shipping/mutations.py@@ -5,7 +5,7 @@ from ...dashboard.shipping.forms import default_shipping_zone_existsfrom ...shipping import modelsfrom ..core.mutations import BaseMutation, ModelDeleteMutation, ModelMutationfrom ..core.scalars import Decimal, WeightScalar-from ..core.utils.error_codes import ShippingErrorCode+from ..core.utils.error_codes import CommonErrorCode, ShippingErrorCodefrom .enums import ShippingMethodTypeEnumfrom .types import ShippingMethod, ShippingZone@@ -56,7 +56,7 @@ class ShippingZoneMixin:{"default": ValidationError("Default shipping zone already exists.",- code=ShippingErrorCode.DEFAULT_SHIPPING_ZONE_ALREADY_EXISTS,+ code=CommonErrorCode.OBJECT_ALREADY_EXISTS,)})diff --git a/saleor/graphql/shop/mutations.py b/saleor/graphql/shop/mutations.pyindex ce2bf3ba23..d0a71bc0d9 100644--- a/saleor/graphql/shop/mutations.py+++ b/saleor/graphql/shop/mutations.py@@ -191,7 +191,7 @@ class AuthorizationKeyAdd(BaseMutation):{"key_type": ValidationError("Authorization key already exists.",- code=CommonErrorCode.AUTHORIZATION_KEY_ALREADY_EXISTS,+ code=CommonErrorCode.OBJECT_ALREADY_EXISTS,)})diff --git a/tests/api/test_account.py b/tests/api/test_account.pyindex 95fe9ce6e0..14fdcbdbae 100644--- a/tests/api/test_account.py+++ b/tests/api/test_account.py@@ -1656,7 +1656,7 @@ def test_set_password_invalid_email(user_api_client):errors = content["data"]["setPassword"]["errors"]assert len(errors) == 1assert errors[0]["field"] == "email"- assert errors[0]["code"] == AccountErrorCode.NOT_USERS_ADDRESS.name+ assert errors[0]["code"] == AccountErrorCode.USER_DOES_NOT_EXIST.namedef test_set_password_invalid_password(user_api_client, customer_user, settings):diff --git a/tests/api/test_discount.py b/tests/api/test_discount.pyindex 79abf1cc50..b702f753ee 100644--- a/tests/api/test_discount.py+++ b/tests/api/test_discount.py@@ -8,7 +8,7 @@ from django_countries import countriesfrom saleor.discount import DiscountValueType, VoucherTypefrom saleor.discount.models import Sale, Voucher-from saleor.graphql.core.utils.error_codes import CheckoutErrorCode+from saleor.graphql.core.utils.error_codes import CommonErrorCodefrom saleor.graphql.discount.enums import DiscountValueTypeEnum, VoucherTypeEnumfrom tests.api.utils import get_graphql_content@@ -265,7 +265,7 @@ def test_create_voucher_with_existing_gift_card_code(errors = content["data"]["voucherCreate"]["errors"]assert len(errors) == 1assert errors[0]["field"] == "promoCode"- assert errors[0]["code"] == CheckoutErrorCode.PROMO_CODE_ALREADY_EXISTS.name+ assert errors[0]["code"] == CommonErrorCode.OBJECT_ALREADY_EXISTS.namedef test_create_voucher_with_existing_voucher_code(@@ -292,7 +292,7 @@ def test_create_voucher_with_existing_voucher_code(errors = content["data"]["voucherCreate"]["errors"]assert len(errors) == 1assert errors[0]["field"] == "promoCode"- assert errors[0]["code"] == CheckoutErrorCode.PROMO_CODE_ALREADY_EXISTS.name+ assert errors[0]["code"] == CommonErrorCode.OBJECT_ALREADY_EXISTS.namedef test_update_voucher(staff_api_client, voucher, permission_manage_discounts):diff --git a/tests/api/test_gift_card.py b/tests/api/test_gift_card.pyindex b366c458b8..de5e63bcc1 100644--- a/tests/api/test_gift_card.py+++ b/tests/api/test_gift_card.py@@ -2,7 +2,7 @@ from datetime import dateimport graphene-from saleor.graphql.core.utils.error_codes import AccountErrorCode, CheckoutErrorCode+from saleor.graphql.core.utils.error_codes import AccountErrorCode, CommonErrorCodefrom tests.api.utils import get_graphql_contentfrom .utils import assert_no_permission@@ -284,7 +284,7 @@ def test_create_gift_card_with_existing_voucher_code(errors = content["data"]["giftCardCreate"]["errors"]assert len(errors) == 1assert errors[0]["field"] == "promoCode"- assert errors[0]["code"] == CheckoutErrorCode.PROMO_CODE_ALREADY_EXISTS.name+ assert errors[0]["code"] == CommonErrorCode.OBJECT_ALREADY_EXISTS.namedef test_create_gift_card_with_existing_gift_card_code(@@ -300,7 +300,7 @@ def test_create_gift_card_with_existing_gift_card_code(errors = content["data"]["giftCardCreate"]["errors"]assert len(errors) == 1assert errors[0]["field"] == "promoCode"- assert errors[0]["code"] == CheckoutErrorCode.PROMO_CODE_ALREADY_EXISTS.name+ assert errors[0]["code"] == CommonErrorCode.OBJECT_ALREADY_EXISTS.namedef test_create_gift_card_without_user(staff_api_client, permission_manage_gift_card):diff --git a/tests/api/test_order.py b/tests/api/test_order.pyindex e236114c81..b388f53f0a 100644--- a/tests/api/test_order.py+++ b/tests/api/test_order.py@@ -1625,7 +1625,7 @@ def test_try_payment_action_generates_event(order, staff_user, payment_dummy):order=order, user=staff_user, payment=payment_dummy, func=_test_operation)- assert exc.value.args[0] == {"payment": message}+ assert exc.value.args[0]["payment"].message == messageerror_event = OrderEvent.objects.get() # type: OrderEventassert error_event.type == order_events.OrderEvents.PAYMENT_FAILED