Skip to content

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

Unify sth-does-not-exist error codes

Aleksander Spyrad0fefb7d32c3
diff --git a/saleor/graphql/account/mutations/base.py b/saleor/graphql/account/mutations/base.py
index d02a23173a..964e46ee59 100644
--- a/saleor/graphql/account/mutations/base.py
+++ b/saleor/graphql/account/mutations/base.py
@@ -20,7 +20,7 @@ from ...core.mutations import (
UpdateMetaBaseMutation,
validation_error_to_error_type,
)
-from ...core.utils.error_codes import AccountErrorCode
+from ...core.utils.error_codes import AccountErrorCode, CommonErrorCode
BILLING_ADDRESS_FIELD = "default_billing_address"
SHIPPING_ADDRESS_FIELD = "default_shipping_address"
@@ -75,7 +75,7 @@ class SetPassword(CreateToken):
raise ValidationError(
{
"email": ValidationError(
- "User doesn't exist", code=AccountErrorCode.USER_DOES_NOT_EXIST
+ "User doesn't exist", code=CommonErrorCode.OBJECT_DOES_NOT_EXIST
)
}
)
@@ -126,7 +126,7 @@ class RequestPasswordReset(BaseMutation):
{
"email": ValidationError(
"User with this email doesn't exist",
- code=AccountErrorCode.USER_DOES_NOT_EXIST,
+ code=CommonErrorCode.OBJECT_DOES_NOT_EXIST,
)
}
)
diff --git a/saleor/graphql/account/mutations/deprecated_account.py b/saleor/graphql/account/mutations/deprecated_account.py
index 2782ae61c3..d32a5835c5 100644
--- a/saleor/graphql/account/mutations/deprecated_account.py
+++ b/saleor/graphql/account/mutations/deprecated_account.py
@@ -6,7 +6,7 @@ from ....checkout import AddressType
from ...account.enums import AddressTypeEnum
from ...account.types import Address, AddressInput, User
from ...core.mutations import BaseMutation, ModelMutation
-from ...core.utils.error_codes import AccountErrorCode
+from ...core.utils.error_codes import AccountErrorCode, CommonErrorCode
from .base import BaseCustomerCreate, UserAddressInput
from .deprecated_staff import send_user_password_reset_email
@@ -185,7 +185,7 @@ class CustomerPasswordReset(BaseMutation):
{
"email": ValidationError(
"User with this email doesn't exist",
- code=AccountErrorCode.USER_DOES_NOT_EXIST,
+ code=CommonErrorCode.OBJECT_DOES_NOT_EXIST,
)
}
)
diff --git a/saleor/graphql/account/mutations/deprecated_staff.py b/saleor/graphql/account/mutations/deprecated_staff.py
index 70dcc144fc..1780cd8b45 100644
--- a/saleor/graphql/account/mutations/deprecated_staff.py
+++ b/saleor/graphql/account/mutations/deprecated_staff.py
@@ -7,7 +7,7 @@ from django.utils.http import urlsafe_base64_encode
from ....account import emails, models
from ...core.mutations import BaseMutation
-from ...core.utils.error_codes import AccountErrorCode
+from ...core.utils.error_codes import CommonErrorCode
def send_user_password_reset_email(user, site):
@@ -42,7 +42,7 @@ class PasswordReset(BaseMutation):
{
"email": ValidationError(
"User with this email doesn't exist",
- code=AccountErrorCode.USER_DOES_NOT_EXIST,
+ code=CommonErrorCode.OBJECT_DOES_NOT_EXIST,
)
}
)
diff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.py
index 57d129309c..f204e160dd 100644
--- a/saleor/graphql/checkout/mutations.py
+++ b/saleor/graphql/checkout/mutations.py
@@ -448,7 +448,7 @@ class CheckoutShippingAddressUpdate(BaseMutation, I18nMixin):
{
"checkout_id": ValidationError(
f"Couldn't resolve to a node: {checkout_id}",
- code=CommonErrorCode.DOES_NOT_EXIST,
+ code=CommonErrorCode.OBJECT_DOES_NOT_EXIST,
)
}
)
@@ -552,7 +552,7 @@ class CheckoutShippingMethodUpdate(BaseMutation):
{
"checkout_id": ValidationError(
f"Couldn't resolve to a node: {checkout_id}",
- code=CommonErrorCode.DOES_NOT_EXIST,
+ code=CommonErrorCode.OBJECT_DOES_NOT_EXIST,
)
}
)
@@ -714,7 +714,7 @@ class CheckoutUpdateVoucher(BaseMutation):
{
"voucher_code": ValidationError(
"Voucher with given code does not exist.",
- code=CommonErrorCode.DOES_NOT_EXIST,
+ code=CommonErrorCode.OBJECT_DOES_NOT_EXIST,
)
}
)
diff --git a/saleor/graphql/core/mutations.py b/saleor/graphql/core/mutations.py
index bfb82fdbe7..14c220316c 100644
--- a/saleor/graphql/core/mutations.py
+++ b/saleor/graphql/core/mutations.py
@@ -152,7 +152,7 @@ class BaseMutation(graphene.Mutation):
{
field: ValidationError(
"Couldn't resolve to a node: %s" % node_id,
- code=CommonErrorCode.DOES_NOT_EXIST,
+ code=CommonErrorCode.OBJECT_DOES_NOT_EXIST,
)
}
)
diff --git a/saleor/graphql/core/utils/__init__.py b/saleor/graphql/core/utils/__init__.py
index 1b4549244e..4d240d2472 100644
--- a/saleor/graphql/core/utils/__init__.py
+++ b/saleor/graphql/core/utils/__init__.py
@@ -53,7 +53,7 @@ def from_global_id_strict_type(
{
field: ValidationError(
"Couldn't resolve to a node: %s" % global_id,
- code=CommonErrorCode.DOES_NOT_EXIST,
+ code=CommonErrorCode.OBJECT_DOES_NOT_EXIST,
)
}
) from exc
diff --git a/saleor/graphql/core/utils/error_codes.py b/saleor/graphql/core/utils/error_codes.py
index 07dc1fd5f3..fe4744fbf3 100644
--- a/saleor/graphql/core/utils/error_codes.py
+++ b/saleor/graphql/core/utils/error_codes.py
@@ -53,7 +53,6 @@ class AccountErrorCode(Enum):
INVALID_PHONE_NUMBER = "invalid_phone_number"
INVALID_USER_TOKEN = "invalid_user_token"
NOT_USERS_ADDRESS = "not_users_address"
- USER_DOES_NOT_EXIST = "user_does_not_exist"
class CheckoutErrorCode(Enum):
@@ -93,13 +92,11 @@ class OrderErrorCode(Enum):
ORDER_NO_SHIPPING_ADDRESS = "order_no_shipping_address"
QUANTITY_LESS_THAN_ONE = "quantity_less_than_one"
REFUND_MANUAL_PAYMENT = "refund_manual_payment"
- VARIANT_DOES_NOT_EXIST = "variant_does_not_exist"
VOID_INACTIVE_PAYMENT = "void_inactive_payment"
class CommonErrorCode(Enum):
CANNOT_FETCH_TAX_RATES = "cannot_fetch_tax_rates"
- DOES_NOT_EXIST = "does_not_exist"
GRAPHQL_ERROR = "graphql_error"
INCORRECT_VALUE = "incorrect_value"
INVALID_FILE_TYPE = "invalid_file_type"
@@ -108,6 +105,7 @@ class CommonErrorCode(Enum):
MISSING_VALUE = "missing_value"
NON_BLANK_VALUE_REQUIRED = "non_blank_value_required"
OBJECT_ALREADY_EXISTS = "object_already_exists"
+ OBJECT_DOES_NOT_EXIST = "object_does_not_exist"
PARTIAL_PAYMENT_NOT_ALLOWED = "partial_payment_not_allowed"
PAYMENT_ERROR = "payment_error"
POSITIVE_NUMBER_REQUIRED = "positive_number_required"
diff --git a/saleor/graphql/giftcard/mutations.py b/saleor/graphql/giftcard/mutations.py
index 556aa44496..bff22cb4f4 100644
--- a/saleor/graphql/giftcard/mutations.py
+++ b/saleor/graphql/giftcard/mutations.py
@@ -11,7 +11,7 @@ from ...giftcard import models
from ...giftcard.utils import activate_gift_card, deactivate_gift_card
from ..core.mutations import BaseMutation, ModelMutation
from ..core.scalars import Decimal
-from ..core.utils.error_codes import AccountErrorCode
+from ..core.utils.error_codes import CommonErrorCode
from .types import GiftCard
@@ -64,7 +64,7 @@ class GiftCardCreate(ModelMutation):
{
"email": ValidationError(
"Customer with this email doesn't exist.",
- code=AccountErrorCode.USER_DOES_NOT_EXIST,
+ code=CommonErrorCode.OBJECT_DOES_NOT_EXIST,
)
}
)
diff --git a/saleor/graphql/order/utils.py b/saleor/graphql/order/utils.py
index 2febf77b9b..07b8c2fbfa 100644
--- a/saleor/graphql/order/utils.py
+++ b/saleor/graphql/order/utils.py
@@ -1,6 +1,6 @@
from django.core.exceptions import ValidationError
-from ..core.utils.error_codes import OrderErrorCode
+from ..core.utils.error_codes import CommonErrorCode, OrderErrorCode
def validate_total_quantity(order):
@@ -41,7 +41,7 @@ def validate_order_lines(order):
{
"lines": ValidationError(
"Could not create orders with non-existing products.",
- code=OrderErrorCode.VARIANT_DOES_NOT_EXIST,
+ code=CommonErrorCode.OBJECT_DOES_NOT_EXIST,
)
}
)
diff --git a/saleor/graphql/product/mutations/attributes.py b/saleor/graphql/product/mutations/attributes.py
index cdbc8ef85b..20fc79e6ce 100644
--- a/saleor/graphql/product/mutations/attributes.py
+++ b/saleor/graphql/product/mutations/attributes.py
@@ -689,7 +689,7 @@ class ProductTypeReorderAttributes(BaseMutation):
{
"product_type_id": ValidationError(
(f"Couldn't resolve to a product type: {product_type_id}"),
- code=CommonErrorCode.DOES_NOT_EXIST,
+ code=CommonErrorCode.OBJECT_DOES_NOT_EXIST,
)
}
)
@@ -710,7 +710,7 @@ class ProductTypeReorderAttributes(BaseMutation):
{
"moves": ValidationError(
f"Couldn't resolve to an attribute: {move_info.id}",
- code=CommonErrorCode.DOES_NOT_EXIST,
+ code=CommonErrorCode.OBJECT_DOES_NOT_EXIST,
)
}
)
@@ -753,7 +753,7 @@ class AttributeReorderValues(BaseMutation):
{
"attribute_id": ValidationError(
f"Couldn't resolve to an attribute: {attribute_id}",
- code=CommonErrorCode.DOES_NOT_EXIST,
+ code=CommonErrorCode.OBJECT_DOES_NOT_EXIST,
)
}
)
@@ -774,7 +774,7 @@ class AttributeReorderValues(BaseMutation):
{
"moves": ValidationError(
f"Couldn't resolve to an attribute value: {move_info.id}",
- code=CommonErrorCode.DOES_NOT_EXIST,
+ code=CommonErrorCode.OBJECT_DOES_NOT_EXIST,
)
}
)
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.py
index dc3b293e53..9b0007bc48 100644
--- a/saleor/graphql/product/mutations/products.py
+++ b/saleor/graphql/product/mutations/products.py
@@ -251,7 +251,7 @@ class CollectionReorderProducts(BaseMutation):
{
"collection_id": ValidationError(
f"Couldn't resolve to a collection: {collection_id}",
- code=CommonErrorCode.DOES_NOT_EXIST,
+ code=CommonErrorCode.OBJECT_DOES_NOT_EXIST,
)
}
)
@@ -273,7 +273,7 @@ class CollectionReorderProducts(BaseMutation):
{
"moves": ValidationError(
f"Couldn't resolve to a product: {move_info.product_id}",
- code=CommonErrorCode.DOES_NOT_EXIST,
+ code=CommonErrorCode.OBJECT_DOES_NOT_EXIST,
)
}
)
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index ebf8cb255e..52051465a5 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -1414,7 +1414,6 @@ enum ErrorCode {
DELETE_STAFF_ACCOUNT
DELETE_STUFF_ACCOUNT
DELETE_SUPERUSER_ACCOUNT
- DOES_NOT_EXIST
EDIT_NON_DRAFT_ORDER
EMPTY
FULFILL_ORDER_LINE
@@ -1458,6 +1457,7 @@ enum ErrorCode {
NULL
NULL_CHARACTERS_NOT_ALLOWED
OBJECT_ALREADY_EXISTS
+ OBJECT_DOES_NOT_EXIST
ORDER_INVALID_SHIPPING_METHOD
ORDER_NO_PAYMENT
ORDER_NO_SHIPPING_ADDRESS
@@ -1484,9 +1484,7 @@ enum ErrorCode {
UNIQUE
UNIQUE_FOR_DATE
UNKNOWN
- USER_DOES_NOT_EXIST
VALUE_ERROR
- VARIANT_DOES_NOT_EXIST
VARIANT_NO_DIGITAL_CONTENT
VOID_INACTIVE_PAYMENT
VOUCHER_NOT_APPLICABLE
diff --git a/saleor/graphql/shop/mutations.py b/saleor/graphql/shop/mutations.py
index d0a71bc0d9..1291d4ca03 100644
--- a/saleor/graphql/shop/mutations.py
+++ b/saleor/graphql/shop/mutations.py
@@ -232,7 +232,7 @@ class AuthorizationKeyDelete(BaseMutation):
{
"key_type": ValidationError(
"Couldn't resolve authorization key",
- code=CommonErrorCode.DOES_NOT_EXIST,
+ code=CommonErrorCode.OBJECT_DOES_NOT_EXIST,
)
}
)
diff --git a/tests/api/test_account.py b/tests/api/test_account.py
index 14fdcbdbae..0e15b6bc62 100644
--- a/tests/api/test_account.py
+++ b/tests/api/test_account.py
@@ -26,7 +26,7 @@ from saleor.graphql.account.mutations.staff import (
)
from saleor.graphql.core.enums import PermissionEnum
from saleor.graphql.core.utils import str_to_enum
-from saleor.graphql.core.utils.error_codes import AccountErrorCode
+from saleor.graphql.core.utils.error_codes import AccountErrorCode, CommonErrorCode
from saleor.order.models import FulfillmentStatus, Order
from tests.api.utils import get_graphql_content
from tests.utils import create_image
@@ -1656,7 +1656,7 @@ def test_set_password_invalid_email(user_api_client):
errors = content["data"]["setPassword"]["errors"]
assert len(errors) == 1
assert errors[0]["field"] == "email"
- assert errors[0]["code"] == AccountErrorCode.USER_DOES_NOT_EXIST.name
+ assert errors[0]["code"] == CommonErrorCode.OBJECT_DOES_NOT_EXIST.name
def test_set_password_invalid_password(user_api_client, customer_user, settings):
@@ -1736,7 +1736,7 @@ def test_password_reset_email_non_existing_user(
{
"field": "email",
"message": "User with this email doesn't exist",
- "code": AccountErrorCode.USER_DOES_NOT_EXIST.name,
+ "code": CommonErrorCode.OBJECT_DOES_NOT_EXIST.name,
}
]
send_password_reset_mock.assert_not_called()
diff --git a/tests/api/test_base_mutation.py b/tests/api/test_base_mutation.py
index 7f1679b77a..3493716e30 100644
--- a/tests/api/test_base_mutation.py
+++ b/tests/api/test_base_mutation.py
@@ -84,7 +84,7 @@ def test_user_error_nonexistent_id(schema_context):
assert user_errors
assert user_errors[0]["field"] == "productId"
assert user_errors[0]["message"] == "Couldn't resolve to a node"
- assert user_errors[0]["code"] == CommonErrorCode.DOES_NOT_EXIST.name
+ assert user_errors[0]["code"] == CommonErrorCode.OBJECT_DOES_NOT_EXIST.name
def test_user_error_id_of_different_type(product, schema_context):
diff --git a/tests/api/test_gift_card.py b/tests/api/test_gift_card.py
index de5e63bcc1..b876d10931 100644
--- a/tests/api/test_gift_card.py
+++ b/tests/api/test_gift_card.py
@@ -2,7 +2,7 @@ from datetime import date
import graphene
-from saleor.graphql.core.utils.error_codes import AccountErrorCode, CommonErrorCode
+from saleor.graphql.core.utils.error_codes import CommonErrorCode
from tests.api.utils import get_graphql_content
from .utils import assert_no_permission
@@ -351,7 +351,7 @@ def test_create_gift_card_with_incorrect_user_email(
assert len(errors) == 1
assert errors[0]["field"] == "email"
assert errors[0]["message"] == "Customer with this email doesn't exist."
- assert errors[0]["code"] == AccountErrorCode.USER_DOES_NOT_EXIST.name
+ assert errors[0]["code"] == CommonErrorCode.OBJECT_DOES_NOT_EXIST.name
def test_create_gift_card_without_premissions(staff_api_client):