

def _db_set_value(self, v, unused_p, value):
    if (not isinstance(value, Key)):
        raise TypeError(('KeyProperty %s can only be set to Key values; received %r' % (self._name, value)))
    ref = value.reference()
    rv = v.mutable_referencevalue()
    rv.set_app(ref.app())
    if ref.has_name_space():
        rv.set_name_space(ref.name_space())
    for elem in ref.path().element_list():
        rv.add_pathelement().CopyFrom(elem)

dataset/ETHPy150Open GoogleCloudPlatform/datastore-ndb-python/ndb/model.py KeyProperty._db_set_value/original