python - Why the keys of objects are None? -


here class structure

class mapping(ndb.model):   id = ndb.stringproperty()   code = ndb.stringproperty()  class doc(ndb.model):   mappings = ndb.structuredproperty('mapping', repeated=true) 

my code scan data set create series of mapping , add instance of doc. @ end, based on criteria, decide save doc instance or not.

   doc = doc()    data in dataset:      m = mapping(parent=doc)   # need able reference parent      m.put()   # did key instantiated?      doc.mappings.append(m)     if good:      doc.put() 

the problem this:

when try iterate list of mapping of doc.mapping, want print out key of mapping instance.

print m.key.id() 

but error message:

attributeerror: 'nonetype' object has no attribute 'id' 

why 'key' not instantiated after called put method?

models created store in structuredproperties not have key. these entities serialized , stored in property of object. can query on them if have been indexed, not exist independent datastore entities, hence no key. more information can found in https://cloud.google.com/appengine/docs/python/ndb/properties#structured have read between lines somewhat. have @ stored entity in datastore viewer , see there no key created these properties.

even though put() model key component not retained in mapping property.

in case achieve attempting, should storing keys of mapping repeated keyproperty , not structuredproperty.

looking deeper reason this,you go hunting in the code , @ implementation of _retrieve_value uses _values property of model serialize entity dict storing in structuredproperty , key not exist in _values


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -