Closed fabien-michel closed 9 months ago
@fabien-michel I like this discovery about this setting. - and indeed I have the same issue as yourself. I'm sure @bellini666 would appreciate a PR for it. I know I would.
I have a concern about the fixes I proposed. Adding str()
will trigger the translation mechanism, and because the enum loading is done at GraphQL schema init on python code load, it voids the laziness benefit of using gettext_lazy...
I'm not sure if there is a better solution.
I agree that's possibly the only solution right now, and as @sdobbelaere said, I would indeed appreciate a PR for it :)
For a better solution I think we would need to introduce some kind of "laziness" support on strawberry itself for loading descriptions that doesn't rely on django. I'll try to think about something to better solve this in the future... Any ideas here @patrick91 ?
When a django choices is defined using gettext_lazy strings, it makes the "description is a string" check fail in graphql.type.definition.GraphQLEnumValue
The check
is_description(description)
return False if description is of typedjango.utils.functional.lazy.<locals>.__proxy__
Context
Strawberry django's settings
Failing test
in
tests/test_enums.py
Add choice with
gettext_lazy
descriptionPossible fix
As a fix I would suggest to change this line from:
to
It would also be possible to change this line from
to
I can propose a PR if you agree with one of these changes.
Thanks
Upvote & Fund