Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Unify `not-found` and `already-exists` error codes
Marcin Gębala2b8bb76ce23b
diff --git a/saleor/graphql/account/mutations/base.py b/saleor/graphql/account/mutations/base.pyindex 3aa124ba05..ab3abb62ef 100644--- a/saleor/graphql/account/mutations/base.py+++ b/saleor/graphql/account/mutations/base.py@@ -91,8 +91,7 @@ class SetPassword(CreateToken, AccountErrorMixin):raise ValidationError({"email": ValidationError(- "User doesn't exist",- code=AccountErrorCode.OBJECT_DOES_NOT_EXIST,+ "User doesn't exist", code=AccountErrorCode.NOT_FOUND)})@@ -147,7 +146,7 @@ class RequestPasswordReset(BaseAccountMutation):{"email": ValidationError("User with this email doesn't exist",- code=AccountErrorCode.OBJECT_DOES_NOT_EXIST,+ code=AccountErrorCode.NOT_FOUND,)})diff --git a/saleor/graphql/account/mutations/deprecated_account.py b/saleor/graphql/account/mutations/deprecated_account.pyindex 4c577d1168..a2795c8bba 100644--- a/saleor/graphql/account/mutations/deprecated_account.py+++ b/saleor/graphql/account/mutations/deprecated_account.py@@ -185,7 +185,7 @@ class CustomerPasswordReset(BaseMutation):{"email": ValidationError("User with this email doesn't exist",- code=AccountErrorCode.OBJECT_DOES_NOT_EXIST,+ code=AccountErrorCode.NOT_FOUND,)})diff --git a/saleor/graphql/account/mutations/deprecated_staff.py b/saleor/graphql/account/mutations/deprecated_staff.pyindex 1172456c06..713348a6b3 100644--- a/saleor/graphql/account/mutations/deprecated_staff.py+++ b/saleor/graphql/account/mutations/deprecated_staff.py@@ -42,7 +42,7 @@ class PasswordReset(BaseMutation):{"email": ValidationError("User with this email doesn't exist",- code=AccountErrorCode.OBJECT_DOES_NOT_EXIST,+ code=AccountErrorCode.NOT_FOUND,)})diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.pyindex dc4ad711d7..e1e7e17a21 100644--- a/saleor/graphql/checkout/mutations.py+++ b/saleor/graphql/checkout/mutations.py@@ -464,7 +464,7 @@ class CheckoutShippingAddressUpdate(BaseCheckoutMutation, I18nMixin):{"checkout_id": ValidationError(f"Couldn't resolve to a node: {checkout_id}",- code=CheckoutErrorCode.OBJECT_DOES_NOT_EXIST,+ code=CheckoutErrorCode.NOT_FOUND,)})@@ -568,7 +568,7 @@ class CheckoutShippingMethodUpdate(BaseCheckoutMutation):{"checkout_id": ValidationError(f"Couldn't resolve to a node: {checkout_id}",- code=CheckoutErrorCode.OBJECT_DOES_NOT_EXIST,+ code=CheckoutErrorCode.NOT_FOUND,)})@@ -730,7 +730,7 @@ class CheckoutUpdateVoucher(BaseCheckoutMutation):{"voucher_code": ValidationError("Voucher with given code does not exist.",- code=CheckoutErrorCode.OBJECT_DOES_NOT_EXIST,+ code=CheckoutErrorCode.NOT_FOUND,)})diff --git a/saleor/graphql/core/utils/error_codes.py b/saleor/graphql/core/utils/error_codes.pyindex 8a8541db1d..bedb3a823a 100644--- a/saleor/graphql/core/utils/error_codes.py+++ b/saleor/graphql/core/utils/error_codes.py@@ -40,7 +40,7 @@ class AccountErrorCode(Enum):GRAPHQL_ERROR = "graphql_error"INVALID = "invalid"INVALID_PASSWORD = "invalid_password"- OBJECT_DOES_NOT_EXIST = "object_does_not_exist"+ NOT_FOUND = "not_found"PASSWORD_ENTIRELY_NUMERIC = "password_entirely_numeric"PASSWORD_TOO_COMMON = "password_too_common"PASSWORD_TOO_SHORT = "password_too_short"@@ -56,7 +56,7 @@ class CheckoutErrorCode(Enum):INSUFFICIENT_STOCK = "insufficient_stock"INVALID = "invalid"INVALID_SHIPPING_METHOD = "invalid_shipping_method"- OBJECT_DOES_NOT_EXIST = "object_does_not_exist"+ NOT_FOUND = "not_found"PAYMENT_ERROR = "payment_error"QUANTITY_GREATER_THAN_LIMIT = "quantity_greater_than_limit"REQUIRED = "required"@@ -76,7 +76,7 @@ class MenuErrorCode(Enum):INVALID = "invalid"INVALID_MENU_ITEM = "invalid_menu_item"NO_MENU_ITEM_PROVIDED = "no_item_provided"- OBJECT_DOES_NOT_EXIST = "object_does_not_exist"+ NOT_FOUND = "not_found"REQUIRED = "required"TOO_MANY_MENU_ITEMS = "too_many_items"UNIQUE = "unique"@@ -92,7 +92,7 @@ class OrderErrorCode(Enum):FULFILL_ORDER_LINE = "fulfill_order_line"GRAPHQL_ERROR = "graphql_error"INVALID = "invalid"- OBJECT_DOES_NOT_EXIST = "object_does_not_exist"+ NOT_FOUND = "not_found"ORDER_INVALID_SHIPPING_METHOD = "order_invalid_shipping_method"ORDER_NO_SHIPPING_ADDRESS = "order_no_shipping_address"PAYMENT_ERROR = "payment_error"@@ -105,38 +105,36 @@ class OrderErrorCode(Enum):class ProductErrorCode(Enum):+ ALREADY_EXISTS = "already_exists"ATTRIBUTE_ALREADY_ASSIGNED = "attribute_already_assigned"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_DOES_NOT_EXIST = "object_does_not_exist"+ NOT_FOUND = "not_found"REQUIRED = "required"- SKU_ALREADY_EXISTS = "sku_already_exists"UNIQUE = "unique"VARIANT_NO_DIGITAL_CONTENT = "variant_no_digital_content"class ShopErrorCode(Enum):+ ALREADY_EXISTS = "already_exists"CANNOT_FETCH_TAX_RATES = "cannot_fetch_tax_rates"GRAPHQL_ERROR = "graphql_error"INVALID = "invalid"- AUTHORIZATION_KEY_ALREADY_EXISTS = "authorization_key_already_exists"- OBJECT_DOES_NOT_EXIST = "object_does_not_exist"+ NOT_FOUND = "not_found"REQUIRED = "required"UNIQUE = "unique"class ShippingErrorCode(Enum):+ ALREADY_EXISTS = "already_exists"GRAPHQL_ERROR = "graphql_error"INVALID = "invalid"MAX_LESS_THAN_MIN = "max_less_than_min"- DEFAULT_SHIPPING_ZONE_ALREADY_EXISTS = "default_shipping_zone_already_exists"- OBJECT_DOES_NOT_EXIST = "object_does_not_exist"+ NOT_FOUND = "not_found"REQUIRED = "required"UNIQUE = "unique"@@ -145,7 +143,7 @@ class PaymentErrorCode(Enum):BILLING_ADDRESS_NOT_SET = "billing_address_not_set"GRAPHQL_ERROR = "graphql_error"INVALID = "invalid"- OBJECT_DOES_NOT_EXIST = "object_does_not_exist"+ NOT_FOUND = "not_found"PARTIAL_PAYMENT_NOT_ALLOWED = "partial_payment_not_allowed"PAYMENT_ERROR = "payment_error"REQUIRED = "required"@@ -153,10 +151,10 @@ class PaymentErrorCode(Enum):class GiftcardErrorCode(Enum):+ ALREADY_EXISTS = "already_exists"GRAPHQL_ERROR = "graphql_error"INVALID = "invalid"- OBJECT_DOES_NOT_EXIST = "object_does_not_exist"- PROMO_CODE_ALREADY_EXISTS = "promo_code_already_exists"+ NOT_FOUND = "not_found"REQUIRED = "required"UNIQUE = "unique"@@ -165,7 +163,7 @@ class ExtensionsErrorCode(Enum):GRAPHQL_ERROR = "graphql_error"INVALID = "invalid"PLUGIN_MISCONFIGURED = "plugin-misconfigured"- OBJECT_DOES_NOT_EXIST = "object_does_not_exist"+ NOT_FOUND = "not_found"REQUIRED = "required"UNIQUE = "unique"diff --git a/saleor/graphql/giftcard/mutations.py b/saleor/graphql/giftcard/mutations.pyindex 5de8afefee..7913fa7889 100644--- a/saleor/graphql/giftcard/mutations.py+++ b/saleor/graphql/giftcard/mutations.py@@ -80,7 +80,7 @@ class GiftCardCreate(GiftcardErrorMixin, ModelMutation):{"email": ValidationError("Customer with this email doesn't exist.",- code=GiftcardErrorCode.OBJECT_DOES_NOT_EXIST,+ code=GiftcardErrorCode.NOT_FOUND,)})diff --git a/saleor/graphql/order/utils.py b/saleor/graphql/order/utils.pyindex 52d04a641d..dd008b220b 100644--- a/saleor/graphql/order/utils.py+++ b/saleor/graphql/order/utils.py@@ -41,7 +41,7 @@ def validate_order_lines(order):{"lines": ValidationError("Could not create orders with non-existing products.",- code=OrderErrorCode.OBJECT_DOES_NOT_EXIST,+ code=OrderErrorCode.NOT_FOUND,)})diff --git a/saleor/graphql/product/mutations/attributes.py b/saleor/graphql/product/mutations/attributes.pyindex 8aebd13d9d..ca990f6450 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.ATTRIBUTE_VALUE_ALREADY_EXISTS+ msg, code=ProductErrorCode.ALREADY_EXISTS)})@@ -185,7 +185,7 @@ class AttributeMixin:{"slug": ValidationError("This attribute's slug already exists.",- code=ProductErrorCode.ATTRIBUTE_SLUG_ALREADY_EXISTS,+ code=ProductErrorCode.ALREADY_EXISTS,)})@@ -544,7 +544,7 @@ def validate_value_is_unique(attribute: models.Attribute, value: models.Attribut{"name": ValidationError(f"Value with slug {value.slug} already exists.",- code=ProductErrorCode.ATTRIBUTE_SLUG_ALREADY_EXISTS,+ code=ProductErrorCode.ALREADY_EXISTS,)})@@ -688,7 +688,7 @@ class ProductTypeReorderAttributes(BaseProductMutation):{"product_type_id": ValidationError((f"Couldn't resolve to a product type: {product_type_id}"),- code=ProductErrorCode.OBJECT_DOES_NOT_EXIST,+ code=ProductErrorCode.NOT_FOUND,)})@@ -709,7 +709,7 @@ class ProductTypeReorderAttributes(BaseProductMutation):{"moves": ValidationError(f"Couldn't resolve to an attribute: {move_info.id}",- code=ProductErrorCode.OBJECT_DOES_NOT_EXIST,+ code=ProductErrorCode.NOT_FOUND,)})@@ -752,7 +752,7 @@ class AttributeReorderValues(BaseProductMutation):{"attribute_id": ValidationError(f"Couldn't resolve to an attribute: {attribute_id}",- code=ProductErrorCode.OBJECT_DOES_NOT_EXIST,+ code=ProductErrorCode.NOT_FOUND,)})@@ -773,7 +773,7 @@ class AttributeReorderValues(BaseProductMutation):{"moves": ValidationError(f"Couldn't resolve to an attribute value: {move_info.id}",- code=ProductErrorCode.OBJECT_DOES_NOT_EXIST,+ code=ProductErrorCode.NOT_FOUND,)})diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.pyindex 78afe56573..587a6bcbc7 100644--- a/saleor/graphql/product/mutations/products.py+++ b/saleor/graphql/product/mutations/products.py@@ -251,7 +251,7 @@ class CollectionReorderProducts(BaseProductMutation):{"collection_id": ValidationError(f"Couldn't resolve to a collection: {collection_id}",- code=ProductErrorCode.OBJECT_DOES_NOT_EXIST,+ code=ProductErrorCode.NOT_FOUND,)})@@ -273,7 +273,7 @@ class CollectionReorderProducts(BaseProductMutation):{"moves": ValidationError(f"Couldn't resolve to a product: {move_info.product_id}",- code=ProductErrorCode.OBJECT_DOES_NOT_EXIST,+ code=ProductErrorCode.NOT_FOUND,)})@@ -756,7 +756,7 @@ class ProductCreate(ModelProductMutation):{"sku": ValidationError("Product with this SKU already exists.",- code=ProductErrorCode.SKU_ALREADY_EXISTS,+ code=ProductErrorCode.ALREADY_EXISTS,)})@@ -832,7 +832,7 @@ class ProductUpdate(ProductCreate):{"sku": ValidationError("Product with this SKU already exists.",- code=ProductErrorCode.SKU_ALREADY_EXISTS,+ code=ProductErrorCode.ALREADY_EXISTS,)})diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 6d5e5f2611..6ee7988064 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -48,7 +48,7 @@ enum AccountErrorCode {GRAPHQL_ERRORINVALIDINVALID_PASSWORD- OBJECT_DOES_NOT_EXIST+ NOT_FOUNDPASSWORD_ENTIRELY_NUMERICPASSWORD_TOO_COMMONPASSWORD_TOO_SHORT@@ -690,7 +690,7 @@ enum CheckoutErrorCode {INSUFFICIENT_STOCKINVALIDINVALID_SHIPPING_METHOD- OBJECT_DOES_NOT_EXIST+ NOT_FOUNDPAYMENT_ERRORQUANTITY_GREATER_THAN_LIMITREQUIRED@@ -1534,6 +1534,7 @@ enum ExtensionsErrorCode {GRAPHQL_ERRORINVALIDPLUGIN_MISCONFIGURED+ NOT_FOUNDREQUIREDUNIQUE}@@ -1684,10 +1685,10 @@ type GiftcardError {}enum GiftcardErrorCode {+ ALREADY_EXISTSGRAPHQL_ERRORINVALID- OBJECT_DOES_NOT_EXIST- PROMO_CODE_ALREADY_EXISTS+ NOT_FOUNDREQUIREDUNIQUE}@@ -1828,7 +1829,7 @@ enum MenuErrorCode {INVALIDINVALID_MENU_ITEMNO_MENU_ITEM_PROVIDED- OBJECT_DOES_NOT_EXIST+ NOT_FOUNDREQUIREDTOO_MANY_MENU_ITEMSUNIQUE@@ -2340,7 +2341,7 @@ enum OrderErrorCode {FULFILL_ORDER_LINEGRAPHQL_ERRORINVALID- OBJECT_DOES_NOT_EXIST+ NOT_FOUNDORDER_INVALID_SHIPPING_METHODORDER_NO_SHIPPING_ADDRESSPAYMENT_ERROR@@ -2674,7 +2675,7 @@ enum PaymentErrorCode {BILLING_ADDRESS_NOT_SETGRAPHQL_ERRORINVALID- OBJECT_DOES_NOT_EXIST+ NOT_FOUNDPARTIAL_PAYMENT_NOT_ALLOWEDPAYMENT_ERRORREQUIRED@@ -2883,18 +2884,16 @@ type ProductError {}enum ProductErrorCode {+ ALREADY_EXISTSATTRIBUTE_ALREADY_ASSIGNEDATTRIBUTE_BAD_VALUEATTRIBUTE_CANNOT_BE_ASSIGNEDATTRIBUTE_DISABLED_VARIANTS- ATTRIBUTE_SLUG_ALREADY_EXISTS- ATTRIBUTE_VALUE_ALREADY_EXISTSGRAPHQL_ERRORINVALIDNOT_PRODUCTS_IMAGE- OBJECT_DOES_NOT_EXIST+ NOT_FOUNDREQUIRED- SKU_ALREADY_EXISTSUNIQUEVARIANT_NO_DIGITAL_CONTENT}@@ -3520,11 +3519,11 @@ type ShippingError {}enum ShippingErrorCode {+ ALREADY_EXISTSGRAPHQL_ERRORINVALIDMAX_LESS_THAN_MIN- DEFAULT_SHIPPING_ZONE_ALREADY_EXISTS- OBJECT_DOES_NOT_EXIST+ NOT_FOUNDREQUIREDUNIQUE}@@ -3690,11 +3689,11 @@ type ShopError {}enum ShopErrorCode {+ ALREADY_EXISTSCANNOT_FETCH_TAX_RATESGRAPHQL_ERRORINVALID- AUTHORIZATION_KEY_ALREADY_EXISTS- OBJECT_DOES_NOT_EXIST+ NOT_FOUNDREQUIREDUNIQUE}diff --git a/saleor/graphql/shipping/mutations.py b/saleor/graphql/shipping/mutations.pyindex 9851ed05f9..b8436f6392 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.DEFAULT_SHIPPING_ZONE_ALREADY_EXISTS,+ code=ShippingErrorCode.ALREADY_EXISTS,)})diff --git a/saleor/graphql/shop/mutations.py b/saleor/graphql/shop/mutations.pyindex ab7610e8c4..d5fcbe2648 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.AUTHORIZATION_KEY_ALREADY_EXISTS,+ code=ShopErrorCode.ALREADY_EXISTS,)})@@ -248,7 +248,7 @@ class AuthorizationKeyDelete(BaseShopMutation):{"key_type": ValidationError("Couldn't resolve authorization key",- code=ShopErrorCode.OBJECT_DOES_NOT_EXIST,+ code=ShopErrorCode.NOT_FOUND,)})diff --git a/tests/api/test_account.py b/tests/api/test_account.pyindex df2e60346d..b3b72fc8d5 100644--- a/tests/api/test_account.py+++ b/tests/api/test_account.py@@ -1668,7 +1668,7 @@ def test_set_password_invalid_email(user_api_client):account_errors = content["data"]["setPassword"]["accountErrors"]assert len(account_errors) == 1assert account_errors[0]["field"] == "email"- assert account_errors[0]["code"] == "OBJECT_DOES_NOT_EXIST"+ assert account_errors[0]["code"] == "NOT_FOUND"def test_set_password_invalid_password(user_api_client, customer_user, settings):diff --git a/tests/api/test_gift_card.py b/tests/api/test_gift_card.pyindex 921f17ec82..4d4ab6e54a 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"] == "PROMO_CODE_ALREADY_EXISTS"+ assert gift_card_errors[0]["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"] == "PROMO_CODE_ALREADY_EXISTS"+ assert gift_card_errors[0]["code"] == "ALREADY_EXISTS"def test_create_gift_card_without_user(staff_api_client, permission_manage_gift_card):@@ -360,7 +360,7 @@ def test_create_gift_card_with_incorrect_user_email(assert errors[0]["message"] == "Customer with this email doesn't exist."gift_card_errors = content["data"]["giftCardCreate"]["giftCardErrors"]- assert gift_card_errors[0]["code"] == "OBJECT_DOES_NOT_EXIST"+ assert gift_card_errors[0]["code"] == "NOT_FOUND"def test_create_gift_card_without_premissions(staff_api_client):