column_property interfering with custom type using TypeDecorator

Issue #1433 resolved
Former user created an issue

So, I have a class like: class Person(SyncClass): """ Base class representing all peoples. Not to be used directly. """ tablename = 'persons' mapper_args = {'polymorphic_identity':'Person'}

uuid = Column(SyncUUID, ForeignKey('syncobjects.uuid'), primary_key=True)

name = Column(SyncUnicode(FT_NAME_LENGTH), nullable=False)

middle_name = Column(SyncUnicode(FT_NAME_LENGTH))

surname = Column(SyncUnicode(FT_NAME_LENGTH), nullable=False)

# The 'info' argument we're passing to the email_address and password columns
# contain metadata that Rum (http://python-rum.org/) can use generate an
# admin interface for your models.

email_address = Column(Unicode(FT_EMAIL_LENGTH), info={'rum': {'field':'Email'}})

business_ref = Column(Integer, ForeignKey('businesses.id'))

created = Column(DateTime, default=datetime.now)

def __init__(self, **kwargs):
    super(Person, self).__init__(**kwargs)

def full_name(self):
    if self.middle_name is not None:
        return "%s %s %s" % (self.name, self.middle_name, self.surname)
    else:
        return "%s %s" % (self.name, self.surname)

Person.fullname = column_property((Person.table.c.name + literal_column("' '") + Person.table.c.surname).label("fullname"))

where SyncUnicode is just a normal custom type

class SyncUnicode(types.TypeDecorator): impl = types.Unicode

def get_xplat_repr(self, name, is_fk=False):
    <nothing important here>

If I use that SyncUnicode definition and populate the database (I'm using TG 2.0) I get a strange error :

AttributeError: 'float' object has no attribute 'decode'

Somehow a 0.0 value is being asked to behave as unicode. This bug has only start manifesting itself after I began using column_property.

It works as expected if I use a type definition based on subclassing, e.g.,

class SyncUnicode(types.Unicode): ....

Comments (1)

  1. Mike Bayer repo owner

    this is more of a mailing list issue. Add the types.Concatenable mixin to your TypeDecorator class so that the addition + operator produces a concatenation instead of numeric addition.

  2. Log in to comment