google-app-enginegoogle-cloud-platformapp-engine-ndbgoogle-app-engine-pythondjangoappengine

google appengine db to ndb migration error: 'model_from_protobuf'


I am in the process of migrating from from db to ndb and i am getting an error in that i do not understand. It is coming from the following line:

return [db.model_from_protobuf(entity_pb.EntityProto(x)) for x in data]

The full error is below:

File

"/base/alloc/tmpfs/dynamic_runtimes/python27g/174489198b39d9fb/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "/base/alloc/tmpfs/dynamic_runtimes/python27g/174489198b39d9fb/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/base/alloc/tmpfs/dynamic_runtimes/python27g/174489198b39d9fb/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/base/data/home/apps/s~proj-/44.427741511160881878/handlers/handler.py", line 329, in dispatch
super(SiteHandler, self).dispatch()
File "/base/data/home/apps/s~proj-/44.427741511160881878/handlers/handler.py", line 130, in dispatch
webapp2.RequestHandler.dispatch(self)
File "/base/alloc/tmpfs/dynamic_runtimes/python27g/174489198b39d9fb/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/base/alloc/tmpfs/dynamic_runtimes/python27g/174489198b39d9fb/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/base/data/home/apps/s~proj-/44.427741511160881878/handlers/site_handlers.py", line 112, in get
self.get_not_logged_in()
File "/base/data/home/apps/s~proj-/44.427741511160881878/handlers/site_handlers.py", line 139, in get_not_logged_in
(missions_memcache_key, missions_expiration)])
File "/base/data/home/apps/s~proj/44.427741511160881878/utils.py", line 368, in cache_get_multi
missing_items[k] = deserialize_entities(missing_items[k])
File "/base/data/home/apps/s~proj-/44.427741511160881878/utils.py", line 277, in deserialize_entities
return [db.model_from_protobuf(entity_pb.EntityProto(x)) for x in data]
AttributeError: 'module' object has no attribute 'model_from_protobuf'

What can i change this to fix it? The documentation has not really been so helpful https://cloud.google.com/appengine/docs/standard/python/ndb/db_to_ndb


Solution

  • The errors seems to come from the fact that you are still using db instead of ndb in that line.

    According to the documentation, you should be able to decode from the protobuf using ndb.LocalStructuredProperty. I have found another question where OP uses the aforementioned method to read from protobuf.

    I have also found a public repository where it uses pb_to_entity to do the transformation but I'm not fully confident about this because of the lack of comments. You should try both methods and see which one do you prefer.