[Sqlalchemy-tickets] Issue #4261: TypeError while using sqlalchemy.Enum with enum.Enum (zzzeek/sqla
Brought to you by:
zzzeek
From: Piotr P. <iss...@bi...> - 2018-05-19 23:01:52
|
New issue 4261: TypeError while using sqlalchemy.Enum with enum.Enum https://bitbucket.org/zzzeek/sqlalchemy/issues/4261/typeerror-while-using-sqlalchemyenum-with Piotr Pokorski: Hi! I'm working on a database, where some of the columns need to have an enumeration/dictionary attribute, so I decided to use a sqlalchemy.Enum type like described in the [doc](http://docs.sqlalchemy.org/en/latest/core/type_basics.html#sqlalchemy.types.Enum). Here is an example showing the problem: ``` #!python import enum import sqlalchemy as db from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class Sizes(enum.Enum): SMALL = 0 MEDIUM = 1 LARGE = 2 class Test(Base): __tablename__ = 'Test' size = db.Column(db.Enum(Sizes), nullable=False) engine = db.create_engine('sqlite:///test.db') Base.metadata.create_all(engine) ``` which throws: ``` #!python Traceback (most recent call last): File "C:/Users/User/PycharmProjects/project/test.py", line 15, in <module> class Test(Base): File "C:/Users/User/PycharmProjects/project/test.py", line 18, in Test size = db.Column(db.Enum(Sizes), nullable=False) File "C:\Python27\lib\site-packages\sqlalchemy\sql\sqltypes.py", line 1296, in __init__ self._enum_init(enums, kw) File "C:\Python27\lib\site-packages\sqlalchemy\sql\sqltypes.py", line 1332, in _enum_init length = max(len(x) for x in self.enums) File "C:\Python27\lib\site-packages\sqlalchemy\sql\sqltypes.py", line 1332, in <genexpr> length = max(len(x) for x in self.enums) TypeError: object of type 'type' has no len() ``` Setup information: ``` #!python Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32 sqlalchemy.__version__ '1.2.7' ``` Thank you for your help! |