Getting the following error when using Django lazy translation inside choice description,
TypeError: The description of the enum value must be a string. when using gettext_lazy in Django choices
from django.utils.translation import gettext_lazy as _
from strawberry_django_plus import gql
class GenderChoices(DjangoTextChoices):
MALE = "M", _("Male")
FEMALE = "F", _("Female")
class CUser(models.Model):
gender = models.CharField(blank=True, null=True, choices=GenderChoices.choices)
@gql.django.filter(CUser, lookups=True)
class CUserFilter:
gender: gql.auto
here is the stack trace
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/home/iroume_prj/venv/lib/python3.11/site-packages/graphql/type/definition.py", line 1456, in fields
fields = resolve_thunk(self._fields)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/iroume_prj/venv/lib/python3.11/site-packages/graphql/type/definition.py", line 300, in resolve_thunk
return thunk() if callable(thunk) else thunk
^^^^^^^
File "/home/iroume_prj/venv/lib/python3.11/site-packages/strawberry/schema/schema_converter.py", line 356, in
fields=lambda: self.get_graphql_input_fields(type_definition),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/iroume_prj/venv/lib/python3.11/site-packages/strawberry/schema/schema_converter.py", line 335, in get_graphql_input_fields
return self.get_thunk_mapping(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/iroume_prj/venv/lib/python3.11/site-packages/strawberry/schema/schema_converter.py", line 319, in get_thunk_mapping
thunk_mapping[name_converter(field)] = field_converter(field)
^^^^^^^^^^^^^^^^^^^^^^
File "/home/iroume_prj/venv/lib/python3.11/site-packages/strawberry/schema/schema_converter.py", line 275, in from_input_field
field_type = cast("GraphQLInputType", self.from_maybe_optional(field.type))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/iroume_prj/venv/lib/python3.11/site-packages/strawberry/schema/schema_converter.py", line 673, in from_maybe_optional
return self.from_type(type.of_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/iroume_prj/venv/lib/python3.11/site-packages/strawberry/schema/schema_converter.py", line 682, in from_type
return self.from_enum(type)
^^^^^^^^^^^^^^^^^^^^^
File "/home/iroume_prj/venv/lib/python3.11/site-packages/strawberry/schema/schema_converter.py", line 162, in from_enum
values={
^
File "/home/iroume_prj/venv/lib/python3.11/site-packages/strawberry/schema/schema_converter.py", line 165, in
): self.from_enum_value(item)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/iroume_prj/venv/lib/python3.11/site-packages/strawberry/schema/schema_converter.py", line 181, in from_enum_value
return GraphQLEnumValue(
^^^^^^^^^^^^^^^^^
File "/home/iroume_prj/venv/lib/python3.11/site-packages/graphql/type/definition.py", line 1316, in init
raise TypeError("The description of the enum value must be a string.")
TypeError: The description of the enum value must be a string.
The above exception was the direct cause of the following exception:
The above error is gone when using a simple str instead of gettext_lazy
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too