python - Workaround to return a list from a ComputedProperty function in NDB -
python - Workaround to return a list from a ComputedProperty function in NDB -
i converting app utilize ndb. used have before:
@db.computedproperty def somecomputedproperty(self, indexed=false): if not self.somecondition: homecoming [] src = self.somereferenceproperty list = src.list1 + src.list2 + src.list3 + src.list4 \ + [src.str1, src.str2] homecoming map(lambda x:'' if not x else x.lower(), list)
as can see, method of generating list bit complicated, prefer maintain way. when started converting ndb, replaced @db.computedproperty
@model.computedproperty
got error:
notimplementederror: property somecomputedproperty not back upwards <type 'list'> types.
i see in model.py
in ext.ndb computedproperty
inherits genericproperty
in _db_set_value
there several if/else statements handle value according type, except there's no handling lists
currently goes through first status , gives out error when homecoming empty list.
is there way work around , avoid error?
you need set repeated=true flag computed property in ndb. don't think can utilize cute "@db.computedproperty" notation, you'll have say:
def _computevalue(self): ...same before... somecomputedproperty = computedproperty(_computevalue, repeated=true, indexed=false)
python google-app-engine gae-datastore python-2.7 app-engine-ndb
Comments
Post a Comment