Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add page errors and update error in validate_slug_value
IKarbowiak533fce570a1d
diff --git a/saleor/graphql/core/enums.py b/saleor/graphql/core/enums.pyindex 7ad821529b..5b10eac871 100644--- a/saleor/graphql/core/enums.py+++ b/saleor/graphql/core/enums.py@@ -10,6 +10,7 @@ from ...extensions.plugins.vatlayer import TaxRateType as CoreTaxRateTypefrom ...giftcard import error_codes as giftcard_error_codesfrom ...menu import error_codes as menu_error_codesfrom ...order import error_codes as order_error_codes+from ...page import error_codes as page_error_codesfrom ...payment import error_codes as payment_error_codesfrom ...product import error_codes as product_error_codesfrom ...shipping import error_codes as shipping_error_codes@@ -90,6 +91,7 @@ ExtensionsErrorCode = graphene.Enum.from_enum(GiftCardErrorCode = graphene.Enum.from_enum(giftcard_error_codes.GiftCardErrorCode)MenuErrorCode = graphene.Enum.from_enum(menu_error_codes.MenuErrorCode)OrderErrorCode = graphene.Enum.from_enum(order_error_codes.OrderErrorCode)+PageErrorCode = graphene.Enum.from_enum(page_error_codes.PageErrorCode)PaymentErrorCode = graphene.Enum.from_enum(payment_error_codes.PaymentErrorCode)ProductErrorCode = graphene.Enum.from_enum(product_error_codes.ProductErrorCode)ShopErrorCode = graphene.Enum.from_enum(shop_error_codes.ShopErrorCode)diff --git a/saleor/graphql/core/types/common.py b/saleor/graphql/core/types/common.pyindex 013b9b9db0..e5c6d73c8b 100644--- a/saleor/graphql/core/types/common.py+++ b/saleor/graphql/core/types/common.py@@ -9,6 +9,7 @@ from ..enums import (GiftCardErrorCode,MenuErrorCode,OrderErrorCode,+ PageErrorCode,PaymentErrorCode,PermissionEnum,ProductErrorCode,@@ -76,6 +77,10 @@ class ShippingError(Error):code = ShippingErrorCode(description="The error code.")+class PageError(Error):+ code = PageErrorCode(description="The error code.")++class PaymentError(Error):code = PaymentErrorCode(description="The error code.")diff --git a/saleor/graphql/core/utils/__init__.py b/saleor/graphql/core/utils/__init__.pyindex e23a530bbd..9c52253854 100644--- a/saleor/graphql/core/utils/__init__.py+++ b/saleor/graphql/core/utils/__init__.py@@ -95,5 +95,5 @@ def validate_slug_value(cleaned_input, slug_field_name: str = "slug"):slug = cleaned_input[slug_field_name]if not slug:raise ValidationError(- f"{slug_field_name} cannot by blank.", code="required"+ f"{slug_field_name.capitalize()} value cannot be blank.")diff --git a/saleor/graphql/page/mutations.py b/saleor/graphql/page/mutations.pyindex 50487651ce..9b92923e2b 100644--- a/saleor/graphql/page/mutations.py+++ b/saleor/graphql/page/mutations.py@@ -3,8 +3,9 @@ from django.core.exceptions import ValidationErrorfrom ...core.permissions import PagePermissionsfrom ...page import models+from ...page.error_codes import PageErrorCodefrom ..core.mutations import ModelDeleteMutation, ModelMutation-from ..core.types.common import SeoInput+from ..core.types.common import PageError, SeoInputfrom ..core.utils import clean_seo_fields, validate_slug_and_generate_if_needed@@ -34,6 +35,8 @@ class PageCreate(ModelMutation):description = "Creates a new page."model = models.Pagepermissions = (PagePermissions.MANAGE_PAGES,)+ error_type_class = PageError+ error_type_field = "page_errors"@classmethoddef clean_input(cls, info, instance, data):@@ -42,13 +45,9 @@ class PageCreate(ModelMutation):cleaned_input = validate_slug_and_generate_if_needed(instance, "title", cleaned_input)- except ValidationError:+ except ValidationError as e:raise ValidationError(- {- "slug": ValidationError(- "Slug value cannot be blank.", code="required"- )- }+ {"slug": ValidationError(e.message, code=PageErrorCode.REQUIRED)})clean_seo_fields(cleaned_input)return cleaned_input@@ -65,6 +64,8 @@ class PageUpdate(PageCreate):description = "Updates an existing page."model = models.Pagepermissions = (PagePermissions.MANAGE_PAGES,)+ error_type_class = PageError+ error_type_field = "page_errors"class PageDelete(ModelDeleteMutation):@@ -75,3 +76,5 @@ class PageDelete(ModelDeleteMutation):description = "Deletes a page."model = models.Pagepermissions = (PagePermissions.MANAGE_PAGES,)+ error_type_class = PageError+ error_type_field = "page_errors"diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex ec10a40007..f5ebf52212 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -2729,14 +2729,30 @@ type PageCountableEdge {type PageCreate {errors: [Error!]+ pageErrors: [PageError!]page: Page}type PageDelete {errors: [Error!]+ pageErrors: [PageError!]page: Page}+type PageError {+ field: String+ message: String+ code: PageErrorCode+}++enum PageErrorCode {+ GRAPHQL_ERROR+ INVALID+ NOT_FOUND+ REQUIRED+ UNIQUE+}+input PageFilterInput {search: String}@@ -2807,6 +2823,7 @@ input PageTranslationInput {type PageUpdate {errors: [Error!]+ pageErrors: [PageError!]page: Page}