prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  GraphQL error: Expected a value of type "WeightUnitsEnum" but received: kg
  ### Steps to reproduce the problem
  1. Change the default language in the storefront to Portuguese.
  2. Go to Dashboard 2.0. The homepage runs a query which fetches `defaultWeightUnit` field.
  This GraphQL request returns this error: `GraphQL error: Expected a value of type "WeightUnitsEnum" but received: kg`
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `saleor/core/weight.py`
  Content:
  ```
  1 """In Saleor we are using 'weight' instead of a 'mass'.
  2 
  3 For those of us who are earth-bound, weight is what we usually experience.
  4 Mass is a theoretical construct.
  5 Unless we are dealing with inertia and momentum, we are encountering
  6 the attractive force between ourselves and the earth,
  7 the isolated effects of mass alone being a little more esoteric.
  8 
  9 So even though mass is more fundamental, most people think
  10 in terms of weight.
  11 
  12 In the end, it does not really matter unless you travel between
  13 different planets.
  14 """
  15 from decimal import Decimal
  16 from enum import Enum
  17 
  18 from django import forms
  19 from django.contrib.sites.models import Site
  20 from django.core.validators import MinValueValidator
  21 from django.template.loader import render_to_string
  22 from django.utils.translation import pgettext_lazy
  23 from measurement.measures import Weight
  24 
  25 
  26 class WeightUnits:
  27     KILOGRAM = 'kg'
  28     POUND = 'lb'
  29     OUNCE = 'oz'
  30     GRAM = 'g'
  31 
  32     CHOICES = [
  33         (KILOGRAM, pgettext_lazy('Kilogram weight unit symbol', 'kg')),
  34         (POUND, pgettext_lazy('Pound weight unit symbol', 'lb')),
  35         (OUNCE, pgettext_lazy('Ounce weight unit symbol', 'oz')),
  36         (GRAM, pgettext_lazy('Gram weight unit symbol', 'g'))]
  37 
  38 
  39 WeightUnitsEnum = Enum(
  40     'WeightUnitsEnum',
  41     {unit: unit for unit in WeightUnits.CHOICES})
  42 
  43 
  44 def zero_weight():
  45     """Represent the zero weight value."""
  46     return Weight(kg=0)
  47 
  48 
  49 def convert_weight(weight, unit):
  50     # Weight amount from the Weight instance can be retrived in serveral units
  51     # via its properties. eg. Weight(lb=10).kg
  52     converted_weight = getattr(weight, unit)
  53     return Weight(**{unit: converted_weight})
  54 
  55 
  56 def get_default_weight_unit():
  57     site = Site.objects.get_current()
  58     return site.settings.default_weight_unit
  59 
  60 
  61 class WeightInput(forms.TextInput):
  62     template = 'dashboard/shipping/weight_widget.html'
  63     input_type = 'number'
  64 
  65     def format_value(self, value):
  66         if isinstance(value, Weight):
  67             unit = get_default_weight_unit()
  68             if value.unit != unit:
  69                 value = convert_weight(value, unit)
  70             return value.value
  71         return value
  72 
  73     def render(self, name, value, attrs=None, renderer=None):
  74         widget = super().render(name, value, attrs=attrs, renderer=renderer)
  75         unit = get_default_weight_unit()
  76         translated_unit = dict(WeightUnits.CHOICES)[unit]
  77         return render_to_string(
  78             self.template,
  79             {'widget': widget, 'value': value, 'unit': translated_unit})
  80 
  81 
  82 class WeightField(forms.FloatField):
  83     def __init__(self, *args, widget=WeightInput, min_value=0, **kwargs):
  84         if isinstance(widget, type):
  85             widget = widget(attrs={'type': 'number', 'step': 'any'})
  86         super().__init__(*args, widget=widget, **kwargs)
  87         if min_value is not None:
  88             self.validators.append(MinValueValidator(min_value))
  89 
  90     def to_python(self, value):
  91         value = super().to_python(value)
  92         if value is None:
  93             return value
  94         unit = get_default_weight_unit()
  95         return Weight(**{unit: value})
  96 
  97     def validate(self, weight):
  98         if weight is None or weight in self.empty_values:
  99             super().validate(weight)
  100         else:
  101             unit = get_default_weight_unit()
  102             if not isinstance(weight, Weight):
  103                 raise Exception(
  104                     '%r is not a valid weight.' % (weight,))
  105             if weight.unit != unit:
  106                 raise forms.ValidationError(
  107                     'Invalid unit: %r (expected %r).' % (
  108                         weight.unit, unit))
  109             super().validate(weight.value)
  110 
  111     def clean(self, value):
  112         value = value_to_be_validated = self.to_python(value)
  113         self.validate(value_to_be_validated)
  114         if isinstance(value, Weight):
  115             value_to_be_validated = Decimal(value.value)
  116         # default decimal validators can be used for Weight's value only
  117         self.run_validators(value_to_be_validated)
  118         return value
  119
  ```
  
  Path: `saleor/graphql/core/enums.py`
  Content:
  ```
  1 import graphene
  2 
  3 from ...core import TaxRateType as CoreTaxRateType, weight
  4 from ...core.permissions import MODELS_PERMISSIONS
  5 from .utils import str_to_enum
  6 
  7 
  8 class ReportingPeriod(graphene.Enum):
  9     TODAY = 'TODAY'
  10     THIS_MONTH = 'THIS_MONTH'
  11 
  12 
  13 TaxRateType = graphene.Enum(
  14     'TaxRateType',
  15     [(str_to_enum(rate[0]), rate[0]) for rate in CoreTaxRateType.CHOICES])
  16 
  17 
  18 PermissionEnum = graphene.Enum(
  19     'PermissionEnum', [
  20         (str_to_enum(codename.split('.')[1]), codename)
  21         for codename in MODELS_PERMISSIONS])
  22 
  23 
  24 WeightUnitsEnum = graphene.Enum.from_enum(weight.WeightUnitsEnum)
  25
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/saleor/core/weight.py b/saleor/core/weight.py
  --- a/saleor/core/weight.py
  +++ b/saleor/core/weight.py
  @@ -13,7 +13,6 @@
   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 @@
           (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
  --- 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 @@
           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])
  
verification_info: {"golden_diff": "diff --git a/saleor/core/weight.py b/saleor/core/weight.py\n--- a/saleor/core/weight.py\n+++ b/saleor/core/weight.py\n@@ -13,7 +13,6 @@\n different planets.\n \"\"\"\n from decimal import Decimal\n-from enum import Enum\n \n from django import forms\n from django.contrib.sites.models import Site\n@@ -36,11 +35,6 @@\n         (GRAM, pgettext_lazy('Gram weight unit symbol', 'g'))]\n \n \n-WeightUnitsEnum = Enum(\n-    'WeightUnitsEnum',\n-    {unit: unit for unit in WeightUnits.CHOICES})\n-\n-\n def zero_weight():\n     \"\"\"Represent the zero weight value.\"\"\"\n     return Weight(kg=0)\ndiff --git a/saleor/graphql/core/enums.py b/saleor/graphql/core/enums.py\n--- a/saleor/graphql/core/enums.py\n+++ b/saleor/graphql/core/enums.py\n@@ -1,6 +1,7 @@\n import graphene\n \n-from ...core import TaxRateType as CoreTaxRateType, weight\n+from ...core import TaxRateType as CoreTaxRateType\n+from ...core.weight import WeightUnits\n from ...core.permissions import MODELS_PERMISSIONS\n from .utils import str_to_enum\n \n@@ -21,4 +22,6 @@\n         for codename in MODELS_PERMISSIONS])\n \n \n-WeightUnitsEnum = graphene.Enum.from_enum(weight.WeightUnitsEnum)\n+WeightUnitsEnum = graphene.Enum(\n+    'WeightUnitsEnum',\n+    [(str_to_enum(unit[0]), unit[0]) for unit in WeightUnits.CHOICES])\n", "issue": "GraphQL error: Expected a value of type \"WeightUnitsEnum\" but received: kg\n### Steps to reproduce the problem\r\n1. Change the default language in the storefront to Portuguese.\r\n2. Go to Dashboard 2.0. The homepage runs a query which fetches `defaultWeightUnit` field.\r\nThis GraphQL request returns this error: `GraphQL error: Expected a value of type \"WeightUnitsEnum\" but received: kg`\r\n\n", "before_files": [{"content": "\"\"\"In Saleor we are using 'weight' instead of a 'mass'.\n\nFor those of us who are earth-bound, weight is what we usually experience.\nMass is a theoretical construct.\nUnless we are dealing with inertia and momentum, we are encountering\nthe attractive force between ourselves and the earth,\nthe isolated effects of mass alone being a little more esoteric.\n\nSo even though mass is more fundamental, most people think\nin terms of weight.\n\nIn the end, it does not really matter unless you travel between\ndifferent planets.\n\"\"\"\nfrom decimal import Decimal\nfrom enum import Enum\n\nfrom django import forms\nfrom django.contrib.sites.models import Site\nfrom django.core.validators import MinValueValidator\nfrom django.template.loader import render_to_string\nfrom django.utils.translation import pgettext_lazy\nfrom measurement.measures import Weight\n\n\nclass WeightUnits:\n    KILOGRAM = 'kg'\n    POUND = 'lb'\n    OUNCE = 'oz'\n    GRAM = 'g'\n\n    CHOICES = [\n        (KILOGRAM, pgettext_lazy('Kilogram weight unit symbol', 'kg')),\n        (POUND, pgettext_lazy('Pound weight unit symbol', 'lb')),\n        (OUNCE, pgettext_lazy('Ounce weight unit symbol', 'oz')),\n        (GRAM, pgettext_lazy('Gram weight unit symbol', 'g'))]\n\n\nWeightUnitsEnum = Enum(\n    'WeightUnitsEnum',\n    {unit: unit for unit in WeightUnits.CHOICES})\n\n\ndef zero_weight():\n    \"\"\"Represent the zero weight value.\"\"\"\n    return Weight(kg=0)\n\n\ndef convert_weight(weight, unit):\n    # Weight amount from the Weight instance can be retrived in serveral units\n    # via its properties. eg. Weight(lb=10).kg\n    converted_weight = getattr(weight, unit)\n    return Weight(**{unit: converted_weight})\n\n\ndef get_default_weight_unit():\n    site = Site.objects.get_current()\n    return site.settings.default_weight_unit\n\n\nclass WeightInput(forms.TextInput):\n    template = 'dashboard/shipping/weight_widget.html'\n    input_type = 'number'\n\n    def format_value(self, value):\n        if isinstance(value, Weight):\n            unit = get_default_weight_unit()\n            if value.unit != unit:\n                value = convert_weight(value, unit)\n            return value.value\n        return value\n\n    def render(self, name, value, attrs=None, renderer=None):\n        widget = super().render(name, value, attrs=attrs, renderer=renderer)\n        unit = get_default_weight_unit()\n        translated_unit = dict(WeightUnits.CHOICES)[unit]\n        return render_to_string(\n            self.template,\n            {'widget': widget, 'value': value, 'unit': translated_unit})\n\n\nclass WeightField(forms.FloatField):\n    def __init__(self, *args, widget=WeightInput, min_value=0, **kwargs):\n        if isinstance(widget, type):\n            widget = widget(attrs={'type': 'number', 'step': 'any'})\n        super().__init__(*args, widget=widget, **kwargs)\n        if min_value is not None:\n            self.validators.append(MinValueValidator(min_value))\n\n    def to_python(self, value):\n        value = super().to_python(value)\n        if value is None:\n            return value\n        unit = get_default_weight_unit()\n        return Weight(**{unit: value})\n\n    def validate(self, weight):\n        if weight is None or weight in self.empty_values:\n            super().validate(weight)\n        else:\n            unit = get_default_weight_unit()\n            if not isinstance(weight, Weight):\n                raise Exception(\n                    '%r is not a valid weight.' % (weight,))\n            if weight.unit != unit:\n                raise forms.ValidationError(\n                    'Invalid unit: %r (expected %r).' % (\n                        weight.unit, unit))\n            super().validate(weight.value)\n\n    def clean(self, value):\n        value = value_to_be_validated = self.to_python(value)\n        self.validate(value_to_be_validated)\n        if isinstance(value, Weight):\n            value_to_be_validated = Decimal(value.value)\n        # default decimal validators can be used for Weight's value only\n        self.run_validators(value_to_be_validated)\n        return value\n", "path": "saleor/core/weight.py"}, {"content": "import graphene\n\nfrom ...core import TaxRateType as CoreTaxRateType, weight\nfrom ...core.permissions import MODELS_PERMISSIONS\nfrom .utils import str_to_enum\n\n\nclass ReportingPeriod(graphene.Enum):\n    TODAY = 'TODAY'\n    THIS_MONTH = 'THIS_MONTH'\n\n\nTaxRateType = graphene.Enum(\n    'TaxRateType',\n    [(str_to_enum(rate[0]), rate[0]) for rate in CoreTaxRateType.CHOICES])\n\n\nPermissionEnum = graphene.Enum(\n    'PermissionEnum', [\n        (str_to_enum(codename.split('.')[1]), codename)\n        for codename in MODELS_PERMISSIONS])\n\n\nWeightUnitsEnum = graphene.Enum.from_enum(weight.WeightUnitsEnum)\n", "path": "saleor/graphql/core/enums.py"}], "after_files": [{"content": "\"\"\"In Saleor we are using 'weight' instead of a 'mass'.\n\nFor those of us who are earth-bound, weight is what we usually experience.\nMass is a theoretical construct.\nUnless we are dealing with inertia and momentum, we are encountering\nthe attractive force between ourselves and the earth,\nthe isolated effects of mass alone being a little more esoteric.\n\nSo even though mass is more fundamental, most people think\nin terms of weight.\n\nIn the end, it does not really matter unless you travel between\ndifferent planets.\n\"\"\"\nfrom decimal import Decimal\n\nfrom django import forms\nfrom django.contrib.sites.models import Site\nfrom django.core.validators import MinValueValidator\nfrom django.template.loader import render_to_string\nfrom django.utils.translation import pgettext_lazy\nfrom measurement.measures import Weight\n\n\nclass WeightUnits:\n    KILOGRAM = 'kg'\n    POUND = 'lb'\n    OUNCE = 'oz'\n    GRAM = 'g'\n\n    CHOICES = [\n        (KILOGRAM, pgettext_lazy('Kilogram weight unit symbol', 'kg')),\n        (POUND, pgettext_lazy('Pound weight unit symbol', 'lb')),\n        (OUNCE, pgettext_lazy('Ounce weight unit symbol', 'oz')),\n        (GRAM, pgettext_lazy('Gram weight unit symbol', 'g'))]\n\n\ndef zero_weight():\n    \"\"\"Represent the zero weight value.\"\"\"\n    return Weight(kg=0)\n\n\ndef convert_weight(weight, unit):\n    # Weight amount from the Weight instance can be retrived in serveral units\n    # via its properties. eg. Weight(lb=10).kg\n    converted_weight = getattr(weight, unit)\n    return Weight(**{unit: converted_weight})\n\n\ndef get_default_weight_unit():\n    site = Site.objects.get_current()\n    return site.settings.default_weight_unit\n\n\nclass WeightInput(forms.TextInput):\n    template = 'dashboard/shipping/weight_widget.html'\n    input_type = 'number'\n\n    def format_value(self, value):\n        if isinstance(value, Weight):\n            unit = get_default_weight_unit()\n            if value.unit != unit:\n                value = convert_weight(value, unit)\n            return value.value\n        return value\n\n    def render(self, name, value, attrs=None, renderer=None):\n        widget = super().render(name, value, attrs=attrs, renderer=renderer)\n        unit = get_default_weight_unit()\n        translated_unit = dict(WeightUnits.CHOICES)[unit]\n        return render_to_string(\n            self.template,\n            {'widget': widget, 'value': value, 'unit': translated_unit})\n\n\nclass WeightField(forms.FloatField):\n    def __init__(self, *args, widget=WeightInput, min_value=0, **kwargs):\n        if isinstance(widget, type):\n            widget = widget(attrs={'type': 'number', 'step': 'any'})\n        super().__init__(*args, widget=widget, **kwargs)\n        if min_value is not None:\n            self.validators.append(MinValueValidator(min_value))\n\n    def to_python(self, value):\n        value = super().to_python(value)\n        if value is None:\n            return value\n        unit = get_default_weight_unit()\n        return Weight(**{unit: value})\n\n    def validate(self, weight):\n        if weight is None or weight in self.empty_values:\n            super().validate(weight)\n        else:\n            unit = get_default_weight_unit()\n            if not isinstance(weight, Weight):\n                raise Exception(\n                    '%r is not a valid weight.' % (weight,))\n            if weight.unit != unit:\n                raise forms.ValidationError(\n                    'Invalid unit: %r (expected %r).' % (\n                        weight.unit, unit))\n            super().validate(weight.value)\n\n    def clean(self, value):\n        value = value_to_be_validated = self.to_python(value)\n        self.validate(value_to_be_validated)\n        if isinstance(value, Weight):\n            value_to_be_validated = Decimal(value.value)\n        # default decimal validators can be used for Weight's value only\n        self.run_validators(value_to_be_validated)\n        return value\n", "path": "saleor/core/weight.py"}, {"content": "import graphene\n\nfrom ...core import TaxRateType as CoreTaxRateType\nfrom ...core.weight import WeightUnits\nfrom ...core.permissions import MODELS_PERMISSIONS\nfrom .utils import str_to_enum\n\n\nclass ReportingPeriod(graphene.Enum):\n    TODAY = 'TODAY'\n    THIS_MONTH = 'THIS_MONTH'\n\n\nTaxRateType = graphene.Enum(\n    'TaxRateType',\n    [(str_to_enum(rate[0]), rate[0]) for rate in CoreTaxRateType.CHOICES])\n\n\nPermissionEnum = graphene.Enum(\n    'PermissionEnum', [\n        (str_to_enum(codename.split('.')[1]), codename)\n        for codename in MODELS_PERMISSIONS])\n\n\nWeightUnitsEnum = graphene.Enum(\n    'WeightUnitsEnum',\n    [(str_to_enum(unit[0]), unit[0]) for unit in WeightUnits.CHOICES])\n", "path": "saleor/graphql/core/enums.py"}]}