graphql-python / graphql-python/graphene-django
Duplicate types when using SerializerMutation with a Model having "choices"
- Dominant language
- Python
- Stars
- 4.4k
- Forks
- 760
- PR merge metrics
- No merged PRs in 30d
Description
**Note: for support questions, please use stackoverflow**. This repository's issues are reserved for feature requests and bug reports.
* **What is the current behavior?**
When defining a Mutation with the parent SerializerMutation, graphene will try to generate two types with the same name, resulting in the error `AssertionError: Found different types with the same name in the schema: xxx, xxx.`
* **If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem** via
a github repo, https://repl.it or similar.
Define these classes
```
class Demo(models.Model):
class YesNoChoices(models.TextChoices):
YES = "y"
NO = "n"
field_with_choices = models.CharField(max_length=1, choices=YesNoChoices)
class DemoSerializer(serializers.ModelSerializer):
class Meta:
model = Demo
fields = ["field_with_choices"]
class DemoMutation(SerializerMutation):
class Meta:
serializer_class = DemoSerializer
class Mutation(object):
demo_mutation = DemoMutation.Field()
```
then run
```
python manage.py graphql_schema
```
* **What is the expected behavior?**
Types should be created in a clean manner without naming conflicts, resulting in a valid schema.
* **What is the motivation / use case for changing the behavior?**
* **Please tell us about your environment:**
- Version: graphene-django: 2.15.0, python 3.10.6
- Platform: Ubuntu 22.04
* **Other information** (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow)
Most likely relates to graphql-python/graphene#1384, where Enums are used. I cannot seem influence how the SerializerMutation handles the choices, however.
Contributor guide
Assessment
This issue has not been assessed yet.