question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I reference an enum type created by SqlAlchemy mapping ?

See original GitHub issue

Hi:

I would like to reuse an Enum type I’ve mapped in one class. Lets say I had the class Patient:

class Patient(Base):
    __tablename__ = 'patients'
    id = Column(CHAR(32), default=generate_uuid, nullable=False, primary_key=True)
    name = Column(Text)
    sex = Column(Enum('MALE', 'FEMALE', name='Sex'), nullable=False)
from graphene import relay
from graphene_sqlalchemy import SQLAlchemyObjectType

from app.models.patient import Patient as PatientModel


class Patient(SQLAlchemyObjectType):
    class Meta:
        model = PatientModel
        interfaces = (relay.Node,)

That is perfectly mapped to a Sex graphql type. But if I would like to create a new Patient, How can I reference the Sex enum type generated by graphene-sqlalchemy e.g in an input type ?

class CreatePatient(relay.ClientIDMutation):
    class Input:
        name = graphene.String()
        sex = ???

BTW I’m using latest master branch version.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
annshresscommented, Feb 9, 2021

Hi there! Do we have a better way to achieve this, now? apart from doing if...else if.

0reactions
erikwredecommented, May 15, 2022

Since #78 and #98 are merged, I expect this problem to be fixed. @annshress, I don’t know what you are referring to with if...else if. If your problem persists, please open a new issue, including an example of your Models. 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

Best way to do enum in Sqlalchemy? - Stack Overflow
First, import the Python enum, the SQLAlchemy Enum, and your SQLAlchemy declarative base wherever you're going to declare your custom SQLAlchemy ...
Read more >
The Type Hierarchy - SQLAlchemy 1.4 Documentation
The Enum type will make use of the backend's native “ENUM” type if one is available; otherwise, it uses a VARCHAR datatype. An...
Read more >
database - Enum or reference table when dealing with maps
I am using sqlalchemy for my database ORM, which includes an enum type that makes it really easy to use an enum column....
Read more >
Enum HOWTO — Python 3.11.1 documentation
The most interesting thing about enum members is that they are singletons. EnumType creates them all while it is creating the enum class...
Read more >
Using Python enums in SQLAlchemy models
Create a custom field type ; """ Enables passing in a Python enum and storing the enum's *value* in the db. The default...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found