谷歌应用引擎数据库到NDB迁移错误:"model_from_protobuf"



>我正在从db迁移到ndb的过程中,我遇到了一个我不明白的错误。它来自以下行:

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

完整的错误如下:

文件

"/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'

我可以更改什么来修复它?文档并没有那么有用 https://cloud.google.com/appengine/docs/standard/python/ndb/db_to_ndb

错误似乎来自您仍在该行中使用db而不是ndb的事实。

根据文档,您应该能够使用ndb.LocalStructuredProperty从 protobuf 解码。我发现了另一个问题,OP 使用上述方法从 protobuf 读取。

我还找到了一个公共存储库,它使用pb_to_entity进行转换,但由于缺乏评论,我对此没有完全信心。您应该尝试这两种方法,看看您更喜欢哪一种。

最新更新