graphql-python / graphene-django

Build powerful, efficient, and flexible GraphQL APIs with seamless Django integration.
http://docs.graphene-python.org/projects/django/en/latest/
MIT License
4.28k stars 766 forks source link

Serializer mutation choice field creation fails with django-rest-framework 3.15.0 #1507

Closed MrThearMan closed 5 months ago

MrThearMan commented 5 months ago

What is the current behavior?

See title. This is due to an isinstance check in converters.get_choices that changes the iterable if the choices are an OrderedDict. Django REST Framework 3.15.0 changed from OrderedDicts to regular dicts, so this check no longer converts the iterable, meaning the loop now tries to iterate the dict by keys, but unpack it to two variables, which is not possible.

I've created an example repo reproducing the issue: https://github.com/MrThearMan/graphene-django-bug. The repo contains the exact traceback for the error.

What is the expected behavior?

I should be able to use serializer mutations with choice fields in DRF 3.15.0.

Changing the isinstance check to isinstance(choices, dict) should solve the issue without any breaking anything for older versions of DRF, as OrderedDicts are subclasses of dicts.

MrThearMan commented 5 months ago

Seems like there is already a pull request for this: https://github.com/graphql-python/graphene-django/pull/1506. Should've checked those first 😄

kiendang commented 5 months ago

@MrThearMan #1506 has been merged. Please check if that fixes the issue. Feel free to reopen the issue if that's not the case.

MrThearMan commented 5 months ago

Thanks, works like a charm! A patch release for this would be much appreciated!

MrThearMan commented 5 months ago

@kiendang Would you be able to release a v3.2.1 with this fix to PyPI?

kiendang commented 5 months ago

Pinging @firaskafri. When you have time could you look at making a patch release v3.2.1? Thanks!

MrThearMan commented 5 months ago

@kiendang @firaskafri Any updates on the PyPI?