[Sqlalchemy-tickets] [sqlalchemy] #2744: Custom TypeDecorator can no longer convert boolean type to
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2013-06-05 16:51:51
|
#2744: Custom TypeDecorator can no longer convert boolean type to another type
-------------------------+---------------------------------------
Reporter: vladimir-lu | Owner: zzzeek
Type: defect | Status: new
Priority: medium | Milestone: 0.8.xx
Component: sql | Severity: minor - half an hour
Keywords: | Progress State: awaiting triage
-------------------------+---------------------------------------
This is a 0.8.0 -> 0.8.1 regression. Basically, I have a custom type
decorator like the following:
{{{
class BitIndicatorType(types.TypeDecorator):
"""
Converts '0' and '1' bits to True/False values and vica-versa
"""
impl = types.SmallInteger
def process_bind_param(self, value, dialect):
return 1 if value else 0
def process_result_value(self, value, dialect):
return True if value == 1 else False
def copy(self):
return BitIndicatorType()
}}}
This type in turn is used in ORM mapped objects and in queries - so for
example if we have enabledInd = Column('enabled_ind', BitIndicatorType)
and obj.enabledInd == True then I expect the SQL to be: {{{... where
enabled_ind = 1...}}}
However, due to
https://github.com/zzzeek/sqlalchemy/commit/5884c2e7e5b46cee29b90aa3f7161e7380e3e2a5
the explicit boolean check added in expression.py _const_expr, the true
gets passed to the dialect directly before being passed through the type
decorator.
The expected behaviour is that the type decorator be checked even when the
value is a boolean value.
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2744>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|