Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide setting to enable/disable converting choices to enums globally #1477

Merged

Conversation

Flauschbaellchen
Copy link
Contributor

@Flauschbaellchen Flauschbaellchen commented Nov 15, 2023

In our project we want to disable the auto-convertion of Django choice fields to Enums for every model.
To specify convert_choices_to_enum = False on every Type is a bit cumbersome so a global setting would help a lot.

Any feedback is highly appreciated.

Closes #1480

@Flauschbaellchen Flauschbaellchen force-pushed the setting-convert-choices-to-enum branch 3 times, most recently from 95fb235 to e9632d1 Compare November 15, 2023 12:58
):
if registry is not None:
converted = registry.get_converted_field(field)
if converted:
return converted
choices = getattr(field, "choices", None)
if convert_choices_to_enum is None:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A reason why I moved it into convert_django_field_with_choices and not implemented it on construct_fields or DjangoObjectType is, that django-graphene-plus uses convert_django_field_with_choices directly and would skip/ignore the setting or would need to manually look it up.
See: https://github.com/0soft/graphene-django-plus/blob/master/graphene_django_plus/input_types.py#L28

Copy link
Collaborator

@kiendang kiendang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Flauschbaellchen for the PR. This sounds like a valid use case to me and the changes you proposed look backward-compatible too. I don't see a problem with merging this. Thoughts @sjdemartini @firaskafri?

Copy link
Collaborator

@sjdemartini sjdemartini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look good to me! Thanks for adding the thorough tests and for suggesting this; the motivation makes sense to me. I support merging 👍

@kiendang kiendang added this to the v3.2.0 milestone Dec 3, 2023
@kiendang kiendang merged commit c416a2b into graphql-python:main Dec 20, 2023
12 checks passed
superlevure pushed a commit to loft-orbital/graphene-django that referenced this pull request Jan 30, 2024
graphql-python#1477)

Co-authored-by: Firas Kafri <3097061+firaskafri@users.noreply.github.com>
Co-authored-by: Kien Dang <mail@kien.ai>
@Flauschbaellchen Flauschbaellchen deleted the setting-convert-choices-to-enum branch May 20, 2024 14:40
@Flauschbaellchen Flauschbaellchen restored the setting-convert-choices-to-enum branch May 20, 2024 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide setting to enable/disable converting choices to enums globally
4 participants