-
Notifications
You must be signed in to change notification settings - Fork 764
Different types with the same name in the schema - Django fields with choices #185
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
Comments
Getting same AssertionError: Found different types with the same name in the schema: PartMarketState, PartMarketState. This is using django-fsm (functional state machine) which is guess creates set of enums as well |
I getting a same error.
|
It seems you're not allowed to include When I changed the field's name to |
Still have this issue after renaming of models fields. |
Is it documented anywhere that we can not use field name |
@darkowic I was wondering why I was getting this error. Now that you mention, the problematic model has a |
This is quite a glaring bug to still have. What can be done about it? Thoughts? |
When If it was And you probably already have your own
So there is This conversion raised a lot of questions already: https://github.com/graphql-python/graphene-django/issues?q=is%3Aissue+choices Maybe someone adds Until then I am going to monkey-patch it somewhere before schema is imported, for example in settings file. Patch: https://gist.github.com/denis-ryzhkov/fcb944f6ebfad4775efb74848703f0d7 |
@denis-ryzhkov thanks for the investigation! You're right, the issues seems to be that the auto naming of the Enum field that a Django choice field gets converted to is likely to clash with an existing type in your schema since it's just the object type name plus the field name:
I think the fix for that is make the generated name more explicit and less likely to clash with anything in the schema. Something like Separately, disabling the conversion of Django choice fields to Enums is a good idea since it's not always desired. Though I think it's probably something that should be done on a field level rather than globally. |
I fixed it by just using the import statement. I imported the type from another class instead of rewriting it again. But that maybe does not solve the issues if you overwrite a class |
I have also had this issue and @denis-ryzhkov explanation helped me resolve the issue. I have a model
As a result, I was getting:
After reading through this, I just changed the class name to |
I also encountered the same error and renaming the field |
It's generally not a good idea to use this as a variable name in Python, as you're overwriting the built-in |
There is a difference between reserved keywords that cannot be used as identifiers vs built-in identifiers that are always available (either without import or via Both This shadowing usually happens on the class definition level, where built-in functions like Once such class fields are defined, Imagine So please either document this poor design decision and its workaround or solve it somehow |
I mixed them up, woops!
I appreciate this hasn't been looked at yet. I'm a new collaborator to this project, I'll see what I can do to make sure this bug is added to a list of top priority things. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Looks like this is still an issue. Don't close |
I think this can be solved by adding double underscore or something similar to the name (e.g “__OrganizationType” instead of “OrganizationType”). I just got curious about this to be honest. Why does a choice based field have a type? Is it possible to completely remove this auto-generated field type for choice field? |
@GasimGasimzada there is an option in master (not yet released) that allows you to turn off the automatic choice to enum conversion: #674 |
I am trying to figure out why our unit tests don't catch this. We have a test model |
@zbyte64 Isn't it just if the field is named "type"? I have the same issue. |
To fix it you have to use |
This doesn't work if you are using |
Related issue:
So this is not enough, it should be |
I agree. But maybe check first for name collisions first? Otherwise new and very simple projects will have over-complicated names. |
Very good points and I especially like the suggestion of checking for name collisions first to progressively improve this. That way it’s not a breaking change either. I’ll try and create a PR for this as soon as possible. |
@jkimbo have you had a chance to work on that? Just ran into this, seems like your solution would solve my problems. |
@MisterGlass I have had a look and unfortunately I don’t it would be possible to check for name collisions since the enum name is defined before it has access to the schema. I think the only way to solve this would be an opt in flag to change the naming generation. Currently not sure if this should be per object type or globally for the whole schema. Anyone have any suggestions? |
I think using the long names without checking for name collisions is fine. Certainly better than the collisions IMO. |
@MisterGlass @arielnmz would it be very disruptive for you we added a global option to change all enums generated from field choices to the new long name format? It would be all or nothing. |
Not at all. I think its an excellent middle ground and by the way aligns pretty well with the actual workarounds I've put in place (at least in my case). |
@jkimbo Sounds fine to me. Another thing I've seen some frameworks do is Just have a configurable string that is part of the generated names. Default is often the project name (EG |
Sorry for the delay with this but I've just created #860 which should resolve the issues in this thread. I would appreciate if people could have a look at the PR to make sure that it would solve your issue in a reasonable way. |
That looks fabulous @jkimbo, thank you |
I am using version 2.10.1 and this definitely hasn't been solved. I have a field called Did I miss something? If not, then what was fixed? |
@rarenatoe have you tried enabling the |
Ah figured it out. I had to add something like this to settings.py:
Might be a good idea to include this in the online docs. |
@rarenatoe it is in the docs: https://docs.graphene-python.org/projects/django/en/latest/settings/#django-choice-field-enum-v3-naming Glad you found it and it works anyway. |
I am also getting this with a field called "status" (instead of "type")... And It appears that this is occuring because I have a |
Did you try creating a type from enum and using that in your queries and mutations?11:44, 18 de agosto de 2020, Coler <[email protected]>:
I am also getting this with a field called "status" (instead of "type")...
—You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or unsubscribe.
-- Sent from Yandex.Mail for mobile
|
@CBuiVNG I tried to use Edit: NVM |
@Instrumedley the solution is right above your post. |
this fixed it for me |
I have a different case -
And I'm getting an error |
it works for me. thanks |
Hi,
When you try to create a model with choices field and then create a second model which inherit from the previous one, you will receive error while schema generating.
Here you have a simple project with models and basic configuration. Try to generate schema and you will get following error:
It seems that it is unable to inherit models with choices fields.
The text was updated successfully, but these errors were encountered: