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.

Enum ChoiceType column results in error

See original GitHub issue

Howdy folks!

The following code produces TypeError: 'MyEnum' object is not iterable, but should work. Note that this is also involves package sqlalchemy_utils

from enum import Enum

class MyEnum(Enum):
   foo = 1
   bar = 2

class MyModel(Base):
    id = Column(sa.Integer, primary_key=True)
    name = Column(sa.Unicode(255))
    type = Column(ChoiceType(MyEnum, impl=Integer()))

class MyObject(SQLAlchemyObjectType):
    class Meta:
        model = MyModel

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
thejcannoncommented, Apr 1, 2019

Sure, but that defeats the automagical nature of using SQLAlchemyObjectType along with model = MyModel 😄. Part of the beauty of this library is that I don’t have to specify the Schema fields, because they are deduced from the SQLAlchemy model.

There’s also the fact that using sqlalchemy.Enum(MyEnum) works but sqlalchemy_utils.ChoiceType(MyEnum) doesn’t 😦.

0reactions
erikwredecommented, Aug 12, 2022

@kurtwiersma if you’re still up for that, feel free to go ahead. It’s probably best to create a new branch for the old release. Would appreciate the effort!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use Enum with SQLAlchemy and Alembic?
First, import the Python enum, the SQLAlchemy Enum, and your SQLAlchemy declarative base wherever you're going to declare your custom SQLAlchemy ...
Read more >
Solved: Disable Button on Data verse Choice column - Expec...
One of the columns is of choice type, called TaskType. I have a button outside of the ... but I'm getting the error,...
Read more >
EnumType Field (Symfony Docs)
A multi-purpose field used to allow the user to "choose" one or more options defined in a PHP enumeration. It extends the ChoiceType...
Read more >
MySQL 8.0 Reference Manual :: 11.3.5 The ENUM Type
If strict SQL mode is enabled, attempts to insert invalid ENUM values result in an error. If an ENUM column is declared to...
Read more >
How to Create Django Like Choices Field in Flask SQLAlchemy
Save yourself all that error handling and enforce at the database level what values are allowed in a field. Python · Flask ·...
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