Skip to content

Latest Graphene Library, Assertion Error on same Enum in Multiple SQL Alchemy Columns #302

Closed
@ShantanuJoshi

Description

@ShantanuJoshi

Hi everyone I know there are quite a few issues documented regarding the assertion error that occurs as a result of the same enum being utilized in two different SQL alchemy mappings with the same column name. I've read through #208, as well as this PR: #210 which in theory should resolve the issue I'm seeing. The other approaches around changing the naming with connections fields seem unnecessary in 2.3 based on the PR and other documentation that such cases are accounted for, but please let me know if I missed a potential solution.

The resulting error is:

AssertionError: Found different types with the same name in the schema: JobStatusEnum, JobStatusEnum.

For context here's my enum, mappings, and graphene setup:

Enum:

import enum
class JobStatusEnum(enum.Enum):
    matched = 1
    interested = 2
    closed = 3
    match_rejected = 4

Mapping (left out extra columns and CinexBase is just a declarative_base(metadata=MetaData("schema_name")) ):

from sqlalchemy import Enum # and some other things

class SavedJobs(CinexBase):
    __tablename__ = 'saved_jobs'
    job_status = Column('job_status', Enum(JobStatusEnum))

class MatchedJobs(CinexBase):
    __tablename__ = 'matched_jobs'
    job_status = Column('job_status', Enum(JobStatusEnum))

The graphene setup:

class SavedJobsType(SQLAlchemyObjectType):
    class Meta:
        model = SavedJobs
        interfaces = (graphene.relay.Node,)

class MatchedJobsType(SQLAlchemyObjectType):
    class Meta:
        model = MatchedJobs
        interfaces = (graphene.relay.Node,)

Query Class (I have a custom object that adds authentication logic and filtering as a result on top of the graphene-sqlalchemy-filter library though this library simply extends the usage of core graphene-sqlalchemy objects by adding filters. Let me know if y'all think this may be the culprit (https://github.com/art1415926535/graphene-sqlalchemy-filter):

class Query(graphene.ObjectType):
   matched_jobs = AuthModifiedFilterableConnectionField(MatchedJobsType.connection, filters=MatchedJobsFilter())
   saved_jobs = AuthModifiedFilterableConnectionField(SavedJobsType.connection, filters=SavedJobsFilter())

Would appreciate any help. The way I've gotten around this is creating an extra enum class with a slightly different name as such:

class SavedJobs(CinexBase):
    __tablename__ = 'saved_jobs'
    job_status = Column('job_status', Enum(JobStatusEnum))

class MatchedJobs(CinexBase):
    __tablename__ = 'matched_jobs'
    job_status = Column('job_status', Enum(JobStatusEnum2))

Though this solution seems impractical as I would be expected to create multiple copies of the same enum for potentially 5+ tables and attempt to maintain a universal set of options. Defeats the purpose of the enum IMO.

Thanks in advance would love any direction here!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions