Closed
Description
Migrated issue, originally created by Yegor Roganov (@roganov)
I have the following model:
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:
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 has been converted to 0 as expected, while status_1
is of type Enum
.
It works in 0.9.8
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
sqlalchemy-bot commentedon Aug 31, 2015
Changes by Yegor Roganov (@roganov):
sqlalchemy-bot commentedon Aug 31, 2015
Michael Bayer (@zzzeek) wrote:
Hi there -
I need source code please, including your custom type's source as well as the contents of the "items" collection above. Cannot reproduce:
output:
sqlalchemy-bot commentedon Aug 31, 2015
Michael Bayer (@zzzeek) wrote:
not enough information provided
sqlalchemy-bot commentedon Aug 31, 2015
Changes by Michael Bayer (@zzzeek):
sqlalchemy-bot commentedon Aug 31, 2015
Yegor Roganov (@roganov) wrote:
Hi!
In your code, you're providing values for
status
field explicitly, while I want them to be picked up from thedefault
parameter.Custom type:
Complete model:
'items' collection:
[{'description': 'asdfadsf', 'category_id': None, 'performer_id': 1}, {'description': 'asdfasdfasddfasdfasdf', 'category_id': None, 'performer_id': 1}]
Code that fails:
(Sorry, I should've posted more info when opening the issue)
sqlalchemy-bot commentedon Aug 31, 2015
Changes by Michael Bayer (@zzzeek):
sqlalchemy-bot commentedon Aug 31, 2015
Michael Bayer (@zzzeek) wrote:
okey doke, got a patch
sqlalchemy-bot commentedon Aug 31, 2015
Changes by Michael Bayer (@zzzeek):
sqlalchemy-bot commentedon Aug 31, 2015
Michael Bayer (@zzzeek) wrote:
insert statement, 🎫
3288
, where the column type for thedefault-holding column would not be propagated to the compiled
statement in the case where the default was being used,
leading to bind-level type handlers not being invoked.
fixes SQLAlchemy 1.0.8 Core fails to convert to native type #3520
→ c39ff99
sqlalchemy-bot commentedon Aug 31, 2015
Michael Bayer (@zzzeek) wrote:
insert statement, 🎫
3288
, where the column type for thedefault-holding column would not be propagated to the compiled
statement in the case where the default was being used,
leading to bind-level type handlers not being invoked.
fixes SQLAlchemy 1.0.8 Core fails to convert to native type #3520
(cherry picked from commit c39ff99)
→ 161209c
sqlalchemy-bot commentedon Aug 31, 2015
Changes by Michael Bayer (@zzzeek):
sqlalchemy-bot commentedon Aug 31, 2015
Michael Bayer (@zzzeek) wrote:
thanks, this will be out in 1.0.9
sqlalchemy-bot commentedon Aug 31, 2015
Yegor Roganov (@roganov) wrote:
This was super quick, thanks!