Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
fix after code review
Damian Wysocki4961a9afb9c0
diff --git a/saleor/graphql/core/enums.py b/saleor/graphql/core/enums.pyindex 5b568017cd..4532859824 100644--- a/saleor/graphql/core/enums.py+++ b/saleor/graphql/core/enums.py@@ -11,7 +11,7 @@ from ...menu import error_codes as menu_error_codesfrom ...order import error_codes as order_error_codesfrom ...page import error_codes as page_error_codesfrom ...payment import error_codes as payment_error_codes-from ...plugins import error_codes as plugins_error_codes+from ...plugins import error_codes as plugin_error_codesfrom ...plugins.vatlayer.plugin import TaxRateType as CoreTaxRateTypefrom ...product import error_codes as product_error_codesfrom ...shipping import error_codes as shipping_error_codes@@ -87,7 +87,7 @@ WeightUnitsEnum = graphene.Enum(AccountErrorCode = graphene.Enum.from_enum(account_error_codes.AccountErrorCode)CheckoutErrorCode = graphene.Enum.from_enum(checkout_error_codes.CheckoutErrorCode)DiscountErrorCode = graphene.Enum.from_enum(discount_error_codes.DiscountErrorCode)-PluginsErrorCode = graphene.Enum.from_enum(plugins_error_codes.PluginsErrorCode)+PluginErrorCode = graphene.Enum.from_enum(plugin_error_codes.PluginErrorCode)GiftCardErrorCode = graphene.Enum.from_enum(giftcard_error_codes.GiftCardErrorCode)MenuErrorCode = graphene.Enum.from_enum(menu_error_codes.MenuErrorCode)MetadataErrorCode = graphene.Enum.from_enum(core_error_codes.MetadataErrorCode)diff --git a/saleor/graphql/core/types/common.py b/saleor/graphql/core/types/common.pyindex 807c39efce..e18e452c1a 100644--- a/saleor/graphql/core/types/common.py+++ b/saleor/graphql/core/types/common.py@@ -6,7 +6,6 @@ from ..enums import (AccountErrorCode,CheckoutErrorCode,DiscountErrorCode,- PluginsErrorCode,GiftCardErrorCode,MenuErrorCode,MetadataErrorCode,@@ -14,6 +13,7 @@ from ..enums import (PageErrorCode,PaymentErrorCode,PermissionEnum,+ PluginErrorCode,ProductErrorCode,ShippingErrorCode,ShopErrorCode,@@ -112,8 +112,8 @@ class GiftCardError(Error):code = GiftCardErrorCode(description="The error code.", required=True)-class PluginsError(Error):- code = PluginsErrorCode(description="The error code.", required=True)+class PluginError(Error):+ code = PluginErrorCode(description="The error code.", required=True)class StockError(Error):diff --git a/saleor/graphql/core/utils/error_codes.py b/saleor/graphql/core/utils/error_codes.pyindex de72edd2b2..1fd9f49503 100644--- a/saleor/graphql/core/utils/error_codes.py+++ b/saleor/graphql/core/utils/error_codes.py@@ -4,11 +4,11 @@ from ....account.error_codes import AccountErrorCodefrom ....checkout.error_codes import CheckoutErrorCodefrom ....core.error_codes import ShopErrorCodefrom ....discount.error_codes import DiscountErrorCode-from ....plugins.error_codes import PluginsErrorCodefrom ....giftcard.error_codes import GiftCardErrorCodefrom ....menu.error_codes import MenuErrorCodefrom ....order.error_codes import OrderErrorCodefrom ....payment.error_codes import PaymentErrorCode+from ....plugins.error_codes import PluginErrorCodefrom ....product.error_codes import ProductErrorCodefrom ....shipping.error_codes import ShippingErrorCode@@ -44,7 +44,7 @@ SALEOR_ERROR_CODE_ENUMS = [AccountErrorCode,CheckoutErrorCode,DiscountErrorCode,- PluginsErrorCode,+ PluginErrorCode,GiftCardErrorCode,MenuErrorCode,OrderErrorCode,diff --git a/saleor/graphql/plugins/mutations.py b/saleor/graphql/plugins/mutations.pyindex 3ba6b6a0e4..e39b30f387 100644--- a/saleor/graphql/plugins/mutations.py+++ b/saleor/graphql/plugins/mutations.py@@ -1,12 +1,11 @@import graphene-from django.core.exceptions import ValidationErrorfrom ...core.permissions import PluginsPermissions-from ...plugins.error_codes import PluginsErrorCode+from ...plugins.error_codes import PluginErrorCodefrom ...plugins.manager import get_plugins_managerfrom ..core.mutations import BaseMutation-from ..core.types.common import PluginsError+from ..core.types.common import PluginErrorfrom .types import Plugin@@ -41,7 +40,7 @@ class PluginUpdate(BaseMutation):class Meta:description = "Update plugin configuration."permissions = (PluginsPermissions.MANAGE_PLUGINS,)- error_type_class = PluginsError+ error_type_class = PluginErrorerror_type_field = "plugins_errors"@classmethod@@ -54,7 +53,7 @@ class PluginUpdate(BaseMutation):raise ValidationError({"id": ValidationError(- "Plugin doesn't exist", code=PluginsErrorCode.NOT_FOUND+ "Plugin doesn't exist", code=PluginErrorCode.NOT_FOUND)})diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 5f6824d232..eb275b2f35 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -3092,6 +3092,21 @@ type PluginCountableEdge {cursor: String!}+type PluginError {+ field: String+ message: String+ code: PluginErrorCode!+}++enum PluginErrorCode {+ GRAPHQL_ERROR+ INVALID+ PLUGIN_MISCONFIGURED+ NOT_FOUND+ REQUIRED+ UNIQUE+}+input PluginFilterInput {active: Booleansearch: String@@ -3110,7 +3125,7 @@ input PluginSortingInput {type PluginUpdate {errors: [Error!]!plugin: Plugin- pluginsErrors: [PluginsError!]!+ pluginsErrors: [PluginError!]!}input PluginUpdateInput {@@ -3118,21 +3133,6 @@ input PluginUpdateInput {configuration: [ConfigurationItemInput]}-type PluginsError {- field: String- message: String- code: PluginsErrorCode!-}--enum PluginsErrorCode {- GRAPHQL_ERROR- INVALID- PLUGIN_MISCONFIGURED- NOT_FOUND- REQUIRED- UNIQUE-}-input PriceRangeInput {gte: Floatlte: Floatdiff --git a/saleor/graphql/views.py b/saleor/graphql/views.pyindex 9e3e3429c6..37e26caea2 100644--- a/saleor/graphql/views.py+++ b/saleor/graphql/views.py@@ -294,7 +294,7 @@ class GraphQLView(View):else:unhandled_errors_logger.error("A query failed unexpectedly", exc_info=exc)- result["plugins"] = {"exception": {"code": type(exc).__name__}}+ result["extensions"] = {"exception": {"code": type(exc).__name__}}if settings.DEBUG:lines = []@@ -303,7 +303,7 @@ class GraphQLView(View):type(exc), exc, exc.__traceback__):lines.extend(line.rstrip().splitlines())- result["plugins"]["exception"]["stacktrace"] = lines+ result["extensions"]["exception"]["stacktrace"] = linesreturn resultdiff --git a/saleor/plugins/avatax/plugin.py b/saleor/plugins/avatax/plugin.pyindex d958518dd3..46555a309c 100644--- a/saleor/plugins/avatax/plugin.py+++ b/saleor/plugins/avatax/plugin.py@@ -9,7 +9,7 @@ from prices import Money, TaxedMoney, TaxedMoneyRangefrom ...core.taxes import TaxError, TaxType, zero_taxed_moneyfrom ...discount import DiscountInfofrom ..base_plugin import BasePlugin, ConfigurationTypeField-from ..error_codes import PluginsErrorCode+from ..error_codes import PluginErrorCodefrom . import (META_CODE_KEY,META_DESCRIPTION_KEY,@@ -385,5 +385,5 @@ class AvataxPlugin(BasePlugin):)raise ValidationError(error_msg + ", ".join(missing_fields),- code=PluginsErrorCode.PLUGIN_MISCONFIGURED.value,+ code=PluginErrorCode.PLUGIN_MISCONFIGURED.value,)diff --git a/saleor/plugins/error_codes.py b/saleor/plugins/error_codes.pyindex 646e7583d2..ca65ba2a98 100644--- a/saleor/plugins/error_codes.py+++ b/saleor/plugins/error_codes.py@@ -1,7 +1,7 @@from enum import Enum-class PluginsErrorCode(Enum):+class PluginErrorCode(Enum):GRAPHQL_ERROR = "graphql_error"INVALID = "invalid"PLUGIN_MISCONFIGURED = "plugin-misconfigured"diff --git a/saleor/plugins/vatlayer/plugin.py b/saleor/plugins/vatlayer/plugin.pyindex db554ca510..df48ab1c3a 100644--- a/saleor/plugins/vatlayer/plugin.py+++ b/saleor/plugins/vatlayer/plugin.py@@ -9,7 +9,7 @@ from prices import Money, MoneyRange, TaxedMoney, TaxedMoneyRangefrom ...checkout import calculationsfrom ...core.taxes import TaxType-from ...graphql.core.utils.error_codes import PluginsErrorCode+from ...graphql.core.utils.error_codes import PluginErrorCodefrom ..base_plugin import BasePluginfrom . import (DEFAULT_TAX_RATE_NAME,@@ -263,5 +263,5 @@ 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=PluginsErrorCode.PLUGIN_MISCONFIGURED.value,+ code=PluginErrorCode.PLUGIN_MISCONFIGURED.value,)diff --git a/tests/api/test_plugins.py b/tests/api/test_plugins.pyindex 3df869092d..80d64ffe6b 100644--- a/tests/api/test_plugins.py+++ b/tests/api/test_plugins.py@@ -3,7 +3,7 @@ import copyimport pytestfrom saleor.plugins.base_plugin import ConfigurationTypeField-from saleor.plugins.error_codes import PluginsErrorCode+from saleor.plugins.error_codes import PluginErrorCodefrom saleor.plugins.manager import get_plugins_managerfrom saleor.plugins.models import PluginConfigurationfrom tests.api.utils import assert_no_permission, get_graphql_content@@ -321,7 +321,7 @@ def test_plugin_configuration_update_containing_invalid_plugin_name(content = get_graphql_content(response)assert content["data"]["pluginUpdate"]["pluginsErrors"][0] == {"field": "id",- "code": PluginsErrorCode.NOT_FOUND.name,+ "code": PluginErrorCode.NOT_FOUND.name,}diff --git a/tests/api/test_view.py b/tests/api/test_view.pyindex e9d7c30733..0aa5a79347 100644--- a/tests/api/test_view.py+++ b/tests/api/test_view.py@@ -89,7 +89,7 @@ def test_invalid_request_body_with_debug(client):errors = content.get("errors")assert errors == [{- "plugins": {"exception": {"code": "str", "stacktrace": []}},+ "extensions": {"exception": {"code": "str", "stacktrace": []}},"message": "Unable to parse query.",}]