Enums are generating duplicated types
See original GitHub issueI think I read this issue in the past, graphene-django is currently throwing the next exception on my end:
“Found different types with the same name in the schema: currency, currency”
The currency field is just a field with enums
class Test:
CURRENCY = (
("EUR", "EUR"),
("USD", "USD"),
)
currency = models.CharField(
"Operation currency",
max_length=5,
choices=CURRENCY,
default=CURRENCY[0]
)
There is a serializer for this model:
class TestSerializer(serializers.ModelSerializer):
class Meta:
model = Test
fields = [
'id',
'currency',
]
The schema is using the Test
model
class TestNode(DjangoObjectType):
class Meta:
"""Transaction GraphQL Type Metaclass
Modifies the basic behavior of the type
"""
model = Test
filter_fields = {
'currency': ['exact'],
}
interfaces = (node.Relay, )
and there are 2 mutations, one for creation based on the serializer and a custom one:
class CreateTestMutation(SerializerMutation):
class Meta:
serializer_class = TestSerializer
model_operations = [
'create',
]
class UpdateTestinput(InputObjectType):
currency = graphene.String()
class UpdateTestMutation(graphene.Mutation):
id = graphene.String()
currency = graphene.String()
class Arguments:
"""Arguments for the given mutation
It defines which arguments are mandatory for the
given mutation. The id is the one that will be used
for searching and the input is the required object
for the update
"""
id = graphene.String(required=True)
input = UpdateTestInput(required=True)
def mutate(self, info, id, input=None):
test = Test.objects.get(pk=str(id))
for key, value in input.items():
setattr(transaction, key, value)
test.save()
# Notice we return an instance of this mutation
return UpdateTestMutation(
id=id,
currency=transaction.currency,
)
Now, this is currently throwing the next exception when using the latest release (2.6.0):
Found different types with the same name in the schema: currency, currency.
On 2.5.0 this error does not happen.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:10 (1 by maintainers)
Top Results From Across the Web
How can I eliminate duplicated Enum code? - Stack Overflow
Create a type-safe utility class which will load enums by code: The interface comes down to:
Read more >enum — Support for enumerations — Python 3.11.1 ...
The type for Enum and its subclasses. Enum. Base class for creating enumerated ... as well as creating the enum members, properly handling...
Read more >Duplicate enums in service reference - MSDN - Microsoft
Now, the generated Reference.cs contains, literally, hundreds of duplicated properties on each one of its classes, same version, ...
Read more >Proto parser does not detect duplicate enum constant names
Also, enum values use C++ scoping rules, so the both enum names and enum constant names must be unique across the entire scope...
Read more >Use Enumerated Data in Generated Code - MATLAB & Simulink
To specify an integer data type size, derive your enumeration class from the ... the use of duplicate enumeration member names during code...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had the same problem but this was how i solved it: You must not call your Enum class more than once in your schema
Models.py
Schema.py
Regarding the Enum conversion, I see it as a bug, that the string of the member variable instead of the first element in the tuple is used. i.e., given the following enum:
The following query:
Results in the following result:
Instead of what I would expect