Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Replace str() functions on Enums by value in ValidationErrors
IKarbowiakb705ada86364
diff --git a/saleor/checkout/utils.py b/saleor/checkout/utils.pyindex 3e3a053301..a32324d0a2 100644--- a/saleor/checkout/utils.py+++ b/saleor/checkout/utils.py@@ -395,7 +395,7 @@ def add_voucher_code_to_checkout({"promo_code": ValidationError("Voucher is not applicable to that checkout.",- code=str(CheckoutErrorCode.VOUCHER_NOT_APPLICABLE),+ code=CheckoutErrorCode.VOUCHER_NOT_APPLICABLE.value,)})@@ -783,27 +783,27 @@ def clean_checkout(checkout: Checkout, discounts: "DiscountsListType"):if not checkout.shipping_method:raise ValidationError("Shipping method is not set",- code=str(CheckoutErrorCode.SHIPPING_METHOD_NOT_SET),+ code=CheckoutErrorCode.SHIPPING_METHOD_NOT_SET.value,)if not checkout.shipping_address:raise ValidationError("Shipping address is not set",- code=str(CheckoutErrorCode.SHIPPING_ADDRESS_NOT_SET),+ code=CheckoutErrorCode.SHIPPING_ADDRESS_NOT_SET.value,)if not is_valid_shipping_method(checkout, discounts):raise ValidationError("Shipping method is not valid for your shipping address",- code=str(CheckoutErrorCode.INVALID_SHIPPING_METHOD),+ code=CheckoutErrorCode.INVALID_SHIPPING_METHOD.value,)if not checkout.billing_address:raise ValidationError("Billing address is not set",- code=str(CheckoutErrorCode.BILLING_ADDRESS_NOT_SET),+ code=CheckoutErrorCode.BILLING_ADDRESS_NOT_SET.value,)if not is_fully_paid(checkout, discounts):raise ValidationError("Provided payment methods can not cover the checkout's total amount",- code=str(CheckoutErrorCode.CHECKOUT_NOT_FULLY_PAID),+ code=CheckoutErrorCode.CHECKOUT_NOT_FULLY_PAID.value,)diff --git a/saleor/extensions/plugins/avatax/plugin.py b/saleor/extensions/plugins/avatax/plugin.pyindex 174819fa4d..e27622eaea 100644--- a/saleor/extensions/plugins/avatax/plugin.py+++ b/saleor/extensions/plugins/avatax/plugin.py@@ -440,7 +440,7 @@ class AvataxPlugin(BasePlugin):)raise ValidationError(error_msg + ", ".join(missing_fields),- code=str(ExtensionsErrorCode.PLUGIN_MISCONFIGURED),+ code=ExtensionsErrorCode.PLUGIN_MISCONFIGURED.value,)@classmethoddiff --git a/saleor/extensions/plugins/vatlayer/plugin.py b/saleor/extensions/plugins/vatlayer/plugin.pyindex 5be8194209..a45baaa460 100644--- a/saleor/extensions/plugins/vatlayer/plugin.py+++ b/saleor/extensions/plugins/vatlayer/plugin.py@@ -300,7 +300,7 @@ class VatlayerPlugin(BasePlugin):if not settings.VATLAYER_ACCESS_KEY and plugin_configuration.active:raise ValidationError("Cannot be enabled without provided 'settings.VATLAYER_ACCESS_KEY'",- code=str(ExtensionsErrorCode.PLUGIN_MISCONFIGURED),+ code=ExtensionsErrorCode.PLUGIN_MISCONFIGURED.value,)@classmethoddiff --git a/saleor/graphql/checkout/mutations.py b/saleor/graphql/checkout/mutations.pyindex d7377f9e1d..47fb8a5b84 100644--- a/saleor/graphql/checkout/mutations.py+++ b/saleor/graphql/checkout/mutations.py@@ -66,14 +66,14 @@ def clean_shipping_method(if not checkout.is_shipping_required():raise ValidationError(- ERROR_DOES_NOT_SHIP, code=str(CheckoutErrorCode.SHIPPING_NOT_REQUIRED)+ ERROR_DOES_NOT_SHIP, code=CheckoutErrorCode.SHIPPING_NOT_REQUIRED.value)if not checkout.shipping_address:raise ValidationError("Cannot choose a shipping method for a checkout without the ""shipping address.",- code=str(CheckoutErrorCode.SHIPPING_ADDRESS_NOT_SET),+ code=CheckoutErrorCode.SHIPPING_ADDRESS_NOT_SET.value,)valid_methods = get_valid_shipping_methods_for_checkout(checkout, discounts)diff --git a/saleor/graphql/menu/mutations.py b/saleor/graphql/menu/mutations.pyindex 33f0cef89e..f69134a4b6 100644--- a/saleor/graphql/menu/mutations.py+++ b/saleor/graphql/menu/mutations.py@@ -161,7 +161,11 @@ def _validate_menu_item_instance(f"(got {item._meta.verbose_name} ID).")raise ValidationError(- {field: ValidationError(msg, code=str(MenuErrorCode.INVALID_MENU_ITEM))}+ {+ field: ValidationError(+ msg, code=MenuErrorCode.INVALID_MENU_ITEM.value+ )+ })@@ -289,7 +293,7 @@ class MenuItemMove(BaseMutation):{"parent_id": ValidationError("Cannot assign a node to itself.",- code=str(MenuErrorCode.CANNOT_ASSIGN_NODE),+ code=MenuErrorCode.CANNOT_ASSIGN_NODE.value,)})@@ -307,7 +311,7 @@ class MenuItemMove(BaseMutation):"Cannot assign a node as child of ""one of its descendants."),- code=str(MenuErrorCode.CANNOT_ASSIGN_NODE),+ code=MenuErrorCode.CANNOT_ASSIGN_NODE.value,)})diff --git a/saleor/graphql/product/utils.py b/saleor/graphql/product/utils.pyindex 2dc23272a9..fede570fad 100644--- a/saleor/graphql/product/utils.py+++ b/saleor/graphql/product/utils.py@@ -14,19 +14,19 @@ def validate_attribute_input_for_product(instance: models.Attribute, values: Lisreturnraise ValidationError(f"{instance.slug} expects a value but none were given",- code=str(ProductErrorCode.REQUIRED),+ code=ProductErrorCode.REQUIRED.value,)if instance.input_type != AttributeInputType.MULTISELECT and len(values) != 1:raise ValidationError(f"A {instance.input_type} attribute must take only one value",- code=str(ProductErrorCode.INVALID),+ code=ProductErrorCode.INVALID.value,)for value in values:if not value.strip():raise ValidationError(- "Attribute values cannot be blank", code=str(ProductErrorCode.REQUIRED)+ "Attribute values cannot be blank", code=ProductErrorCode.REQUIRED.value)@@ -34,18 +34,18 @@ def validate_attribute_input_for_variant(instance: models.Attribute, values: Lisif not values:raise ValidationError(f"{instance.slug} expects a value but none were given",- code=str(ProductErrorCode.REQUIRED),+ code=ProductErrorCode.REQUIRED.value,)if len(values) != 1:raise ValidationError(f"A variant attribute cannot take more than one value",- code=str(ProductErrorCode.INVALID),+ code=ProductErrorCode.INVALID.value,)if not values[0].strip():raise ValidationError(- "Attribute values cannot be blank", code=str(ProductErrorCode.REQUIRED)+ "Attribute values cannot be blank", code=ProductErrorCode.REQUIRED.value)