[Sqlalchemy-tickets] Issue #3520: SQLAlchemy 1.0.8 Core fails to convert to native type (zzzeek/sql
Brought to you by:
zzzeek
|
From: Yegor R. <iss...@bi...> - 2015-08-31 14:04:30
|
New issue 3520: SQLAlchemy 1.0.8 Core fails to convert to native type https://bitbucket.org/zzzeek/sqlalchemy/issues/3520/sqlalchemy-108-core-fails-to-convert-to Yegor Roganov: I have the following model: ```python class PortfolioItem(Base): class STATUS(Enum): active = 0 deleted = 1 status = Column(EnumInt(STATUS), default=STATUS.active) # ... ``` where `EnumInt` is a custom field (it just converts an enum back and forth). Consider the following statement: ```python PortfolioItem.__table__.insert(items).returning(PortfolioItem.id) ``` This then throws an exception: ``` sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'STATUS' [SQL: 'INSERT INTO portfolio (performer_id, status, date_created, description, category_id) VALUES (%(performer_id_0)s, %(status)s, %(date_created)s, %(description_0)s, %(category_id_0)s), (%(performer_id_1)s, %(status_1)s, %(date_created_1)s, %(description_1)s, %(category_id_1)s) RETURNING portfolio.id'] [parameters: {'description_1': '', 'performer_id_1': 1, 'category_id_1': None, 'category_id_0': None, 'status_1': <STATUS.active: 0>, 'performer_id_0': 1, 'description_0': '', 'date_created_1': datetime.datetime(2015, 8, 31, 13, 43, 58, 366724), 'date_created': datetime.datetime(2015, 8, 31, 13, 43, 58, 366716), 'status': 0}] ``` Note that `status` parameter have been converted to 0 as expected, while `status_1` is of type `Enum`. It works in 0.9.8 |