-
Notifications
You must be signed in to change notification settings - Fork 229
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
AssertionError: Found different types with the same name in the schema #211
Comments
Is |
Yes it is in my mixin |
Then it's the known problem for which I have proposed a solution in #210. It happens when you use the same enum in different columns (or maybe in your case, in a class and a subclass). The enum type is not reused, but created twice with the same name. |
I really could not get to apply your solutions, could you please provide some details, saw your latest commits on improving Enum type creation but can't use it at the moment. is there a quick fix i can try ?
|
You would probably need to somehow patch the SalableProduct to make it use the same enum, when using the current version of graphene-sqlalchemy. I expect the fix will be merged and released soon. |
I use this monkey-patch on my projects: from functools import lru_cache
graphene.Enum.from_enum = lru_cache(maxsize=None)(graphene.Enum.from_enum) |
That is... really creative! Thanks!
|
Your code is not in release 2.2.0.. |
I'm running into this issue. I defined my model like this: class MyModel(db.Model):
status_before = db.Column(db.Enum(AdStatus), nullable=False)
status_during = db.Column(db.Enum(AdStatus), nullable=False) Which fails with:
Versions:
|
I am also getting this error using the same Enum in various SQLAlchemy models. |
So, for the record, I solved this by making global SQLAlchemy types, so @richin13 , your code would become:
|
This problem is caused by multiple enum classes being created with the same definition.
We ran into this problem when creating a custom scalar type and using it in multiple locations. |
when you say "wrapping around our returned class" you don't mean you are using the lru_cache multiple times in your project, right? The lru_cache hack I suggested should be used only once before your SQLAlchemy models are declared. If your model declarations are spread among multiple files, you don't need to write |
Yes, I mean one code location for both solutions. |
I notice sqlalchemy_utils enum is being converted to graphene enum type.
-2 Here.. Not sure if this is triggered automatically: N.B: My models include this section: -3 And here... I trigger the same code here because I need to list the values of the enum. Commenting out this section resolves the issue but I need this list of values! Noticed the LRU cache fix above won't help if you have different enums |
You can turn off the automatic conversion of your enums #98 (comment) This is the solution!!! Spent a day and a half finding it |
I feel like sqlalchemy is building things every time it reads class MyModel(db.Model):
status_before = db.Column(db.Enum(AdStatus), nullable=False)
status_during = db.Column(db.Enum(AdStatus), nullable=False) Does crash. While StatusColumn = db.Enum(AdStatus)
class MyModel(db.Model):
status_before = db.Column(StatusColumn, nullable=False)
status_during = db.Column(StatusColumn, nullable=False) Works fine. If you have an enum declaration next to your model you can even do: import enum
from sqlalchemy import Column, Enum
@Enum
class Status(enum.Enum):
STARTED = 1
CANCELED = 2
class TagType(Base):
status_before = Column(Status, nullable=False)
status_during = Column(Status, nullable=False) |
To solve this issue I created a separate type and imported it in both places I want to use it: import graphene
from my_project.models.core import MyEnum
my_enum = graphene.Enum.from_enum(MyEnum) and then in the query/mutation: from my_project.routes.graphql.types.common import my_enum
class MyMutation(graphene.Mutation)
...
class Arguments:
...
paramName = my_enum(required=True)
... |
@rdemetrescu great solution - I hope this can be merged into graphene |
I have two Classes Products and SalableProducts in my Models (SalableProducts inherits from Products so it has every field of it's database), in my Schema here is what i did
and here is my Query class :
When i run my server i got this error :
AssertionError: Found different types with the same name in the schema: product_status, product_status.
The text was updated successfully, but these errors were encountered: