Skip to content

SQLAlchemy Enum with 'nullable=True' doesn't work correctly #117

Closed
@Lelby

Description

@Lelby

I have SQLAlchemy model with some enum:

variants = ('red', 'green', 'yellow')
my_enum_type = sqlalchemy.dialects.postgresql.ENUM(*variants)

class CarModel(Base):
    color = sqlalchemy.Column(my_enum_type)

and graphene Schema which uses SQLAlchemyObjectType:

class Car(SQLAlchemyObjectType):
    class Meta:
       model = CarModel

I want to create a mutation:

class CreateCar(graphene.Mutation):
    class Arguments:
        color = Car._meta.fields['color'].type

    ...
    def mutate(self, info, color):
        db_session.add(CarModel(color=color))
        db_session.commit()
        return ...

There are two issues:

  1. (Minor) I refer to enum in a strange way: .._meta.fields.., but it is known issue: Proper support for the SQLAlchemy Enum type #78
  2. (Major) If I try to execute program with such schema, I get error:
File "contrib/python/graphene/graphene/types/argument.py", line 67, in to_arguments
    raise ValueError('Unknown argument "{}".'.format(default_name))
ValueError: Unknown argument "color"

If I add nullable=False to SQLAlchemy model, everything works fine.

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