Skip to content

enum member가 str이 아닐 경우 에러 #4

@item4

Description

@item4
tests/reservation_test.py:1: in <module>
    from ***.reservation import Reservation, Traveler, TravelerType
***/reservation.py:83: in <module>
    class Traveler(Base):
***/reservation.py:102: in Traveler
    type = Column(EnumType(TravelerType), nullable=False)
../../.virtualenvs/***/lib/python3.5/site-packages/sqlalchemy_enum34.py:39: in __init__
    super(Enum, self).__init__(*enumerants, **options)
../../.virtualenvs/***/lib/python3.5/site-packages/sqlalchemy/sql/type_api.py:706: in __init__
    self.impl = to_instance(self.__class__.impl, *args, **kwargs)
../../.virtualenvs/***/lib/python3.5/site-packages/sqlalchemy/sql/type_api.py:1162: in to_instance
    return typeobj(*arg, **kw)
../../.virtualenvs/***/lib/python3.5/site-packages/sqlalchemy/sql/sqltypes.py:1135: in __init__
    length = max(len(x) for x in self.enums)
../../.virtualenvs/***/lib/python3.5/site-packages/sqlalchemy/sql/sqltypes.py:1135: in <genexpr>
    length = max(len(x) for x in self.enums)
E   TypeError: object of type 'int' has no len()
class TravelerType(enum.Enum):
    adult = 1
    child = 2
    baby = 3

class Traveler(Base):

    type = Column(EnumType(TravelerType), nullable=False)

아무래도 예외처리를 해줘야 할 것 같습니다.

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