def _update_row(data, klass, dbrow, metadata, value):
    if not value and metadata.nullable:
        value = None
    if metadata.coltype == "RelationshipProperty":
        relmodel = getattr(klass, metadata.colname).property.mapper.class_
        if isinstance(value, list) and value:
            t = dbsession.query(relmodel).filter(
                            relmodel.id.in_([int(i) for i in value])).all()
            if metadata.collection == "MappedCollection":
                t = dict((r.name, r) for r in t)
            setattr(dbrow, metadata.colname, t)
        elif value is None:
            if metadata.uselist:
                value = {} if metadata.collection == "MappedCollection" else []
            setattr(dbrow, metadata.colname, value)
        else:
            value = int(value)
            if value:
                t = dbsession.query(relmodel).get(value)
                if metadata.uselist:
                    t = {t.name: t} if metadata.collection == "MappedCollection" else [t]
                setattr(dbrow, metadata.colname, t)
    elif metadata.coltype == "PickleText":
        if value is None:
            if metadata.nullable:
                setattr(dbrow, metadata.colname, value)
            else:
                setattr(dbrow, metadata.colname, "")
        else:
            try:
                value = eval(value, {}, {})
            except: # allows use of unquoted strings.
                pass
            setattr(dbrow, metadata.colname, value)
    elif metadata.coltype == "TEXT":
        setattr(dbrow, metadata.colname, value)
    else:
        if value is None and metadata.nullable:
            setattr(dbrow, metadata.colname, None)
        else:
            validator = _VALIDATORS.get(metadata.coltype)
            if validator is not None:
                value = validator(value)
            setattr(dbrow, metadata.colname, value)
dataset/ETHPy150Open kdart/pycopia/storage/pycopia/db/webhelpers.py/_update_row/original