TraitText value restricted to max length 255

Trait_text has a sqlalchemy model definition with
value column as Text type, but the migrate scripts
defined the column type as String(255) leading to
Sqlalchemy exception when indexing trait with large
text.

This fixes the TraitText model value as String(255)
to match the migrate script definition and crops
the text input to 255 characters.

Change-Id: I55eee4e9fcdee8d05f3598a9bc0368bc92a9b238
Closes-Bug: 1447647
This commit is contained in:
Rohit Jaiswal 2015-04-28 14:52:38 -07:00
parent 027a236ae8
commit 35e574085d
2 changed files with 4 additions and 3 deletions

View File

@ -121,6 +121,7 @@ class Trait(base.Model):
return float(value)
if trait_type is cls.DATETIME_TYPE:
return timeutils.normalize_time(timeutils.parse_isotime(value))
# Cropping the text value to match the TraitText value size
if isinstance(value, six.binary_type):
return value.decode('utf-8')
return six.text_type(value)
return value.decode('utf-8')[:255]
return six.text_type(value)[:255]

View File

@ -344,7 +344,7 @@ class TraitText(Base):
)
event_id = Column(Integer, ForeignKey('event.id'), primary_key=True)
key = Column(String(255), primary_key=True)
value = Column(Text)
value = Column(String(255))
class TraitInt(Base):