Consider special flags/logic/other in TypeDecorator to ease production of custom `__eq__()` logic

Issue #2744 resolved
Vladimir Lushnikov created an issue

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.

Comments (4)

  1. Log in to comment