Skip to content

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

Fixes #3828, graphQl error 'Expected a value of type WeightUnitsEnum'

jakubwi09f6ae140377
diff --git a/saleor/core/weight.py b/saleor/core/weight.py
index e91822406f..069ba875aa 100644
--- a/saleor/core/weight.py
+++ b/saleor/core/weight.py
@@ -13,7 +13,6 @@ In the end, it does not really matter unless you travel between
different planets.
"""
from decimal import Decimal
-from enum import Enum
from django import forms
from django.contrib.sites.models import Site
@@ -36,11 +35,6 @@ class WeightUnits:
(GRAM, pgettext_lazy('Gram weight unit symbol', 'g'))]
-WeightUnitsEnum = Enum(
- 'WeightUnitsEnum',
- {unit: unit for unit in WeightUnits.CHOICES})
-
-
def zero_weight():
"""Represent the zero weight value."""
return Weight(kg=0)
diff --git a/saleor/graphql/core/enums.py b/saleor/graphql/core/enums.py
index d0df0ebc68..3ebafe0990 100644
--- a/saleor/graphql/core/enums.py
+++ b/saleor/graphql/core/enums.py
@@ -1,6 +1,7 @@
import graphene
-from ...core import TaxRateType as CoreTaxRateType, weight
+from ...core import TaxRateType as CoreTaxRateType
+from ...core.weight import WeightUnits
from ...core.permissions import MODELS_PERMISSIONS
from .utils import str_to_enum
@@ -21,4 +22,6 @@ PermissionEnum = graphene.Enum(
for codename in MODELS_PERMISSIONS])
-WeightUnitsEnum = graphene.Enum.from_enum(weight.WeightUnitsEnum)
+WeightUnitsEnum = graphene.Enum(
+ 'WeightUnitsEnum',
+ [(str_to_enum(unit[0]), unit[0]) for unit in WeightUnits.CHOICES])
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index b1524d5331..a77367e32e 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -2547,8 +2547,8 @@ type Weight {
scalar WeightScalar
enum WeightUnitsEnum {
- kg
- lb
- oz
- g
+ KG
+ LB
+ OZ
+ G
}
diff --git a/saleor/static/dashboard-next/storybook/__snapshots__/Stories.test.ts.snap b/saleor/static/dashboard-next/storybook/__snapshots__/Stories.test.ts.snap
index 3eb8ffd5fd..1e915f53e9 100644
--- a/saleor/static/dashboard-next/storybook/__snapshots__/Stories.test.ts.snap
+++ b/saleor/static/dashboard-next/storybook/__snapshots__/Stories.test.ts.snap
@@ -66923,12 +66923,12 @@ exports[`Storyshots Views / Shipping / Shipping zones list default 1`] = `
role="button"
tabindex="0"
>
- kg
+ KG
</div>
<input
name="unit"
type="hidden"
- value="kg"
+ value="KG"
/>
<svg
aria-hidden="true"
@@ -67233,12 +67233,12 @@ exports[`Storyshots Views / Shipping / Shipping zones list loading 1`] = `
class="MuiSelect-select-id MuiSelect-selectMenu-id MuiSelect-disabled-id MuiInputBase-input-id MuiInput-input-id MuiInputBase-disabled-id MuiInput-disabled-id"
role="button"
>
- kg
+ KG
</div>
<input
name="unit"
type="hidden"
- value="kg"
+ value="KG"
/>
<svg
aria-hidden="true"
@@ -67501,12 +67501,12 @@ exports[`Storyshots Views / Shipping / Shipping zones list no data 1`] = `
role="button"
tabindex="0"
>
- kg
+ KG
</div>
<input
name="unit"
type="hidden"
- value="kg"
+ value="KG"
/>
<svg
aria-hidden="true"
diff --git a/saleor/static/dashboard-next/storybook/stories/shipping/ShippingZonesListPage.tsx b/saleor/static/dashboard-next/storybook/stories/shipping/ShippingZonesListPage.tsx
index 1dadaa6657..15be89a13e 100644
--- a/saleor/static/dashboard-next/storybook/stories/shipping/ShippingZonesListPage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/shipping/ShippingZonesListPage.tsx
@@ -11,7 +11,7 @@ import Decorator from "../../Decorator";
const props: ShippingZonesListPageProps = {
...pageListProps.default,
- defaultWeightUnit: WeightUnitsEnum.kg,
+ defaultWeightUnit: WeightUnitsEnum.KG,
onAdd: () => undefined,
onRemove: () => undefined,
onSubmit: () => undefined,
diff --git a/saleor/static/dashboard-next/types/globalTypes.ts b/saleor/static/dashboard-next/types/globalTypes.ts
index e5e1ff4948..5f4c65a707 100644
--- a/saleor/static/dashboard-next/types/globalTypes.ts
+++ b/saleor/static/dashboard-next/types/globalTypes.ts
@@ -160,10 +160,10 @@ export enum VoucherTypeEnum {
}
export enum WeightUnitsEnum {
- g = "g",
- kg = "kg",
- lb = "lb",
- oz = "oz",
+ G = "G",
+ KG = "KG",
+ LB = "LB",
+ OZ = "OZ",
}
export interface AddressInput {