英文:
"datastore: internal error: server returned the wrong number of entities" when retrieving non-existent object
问题
使用Google App Engine的go API,我尝试检索一个不存在的对象:
func entityKey(c appengine.Context, name string) *datastore.Key {
collectionKey := datastore.NewKey(c, "EntityCollection", "default_entitycollection", 0, nil)
return datastore.NewKey(c, "Entity", name, 0, collectionKey)
}
//.....
var record EntityRecord // 一些随机类型
key := entityKey(context, "This key does not exist")
err := datastore.Get(context, key, &record)
它返回错误信息:
datastore: internal error: server returned the wrong number of entities
而我期望得到更明显的 ErrNoSuchEntity
。这是怎么回事?
这是在本地开发服务器上的情况。
英文:
With the go API for Google App Engine I try to retrieve a non-existent object:
func entityKey(c appengine.Context, name string) *datastore.Key {
collectionKey := datastore.NewKey(c, "EntityCollection", "default_entitycollection", 0, nil)
return datastore.NewKey(c, "Entity", name, 0, collectionKey)
}
//.....
var record EntityRecord // Some random type
key := entityKey(context, "This key does not exist")
err := datastore.Get(context, key, &record)
It returns the error:
datastore: internal error: server returned the wrong number of entities
Whereas I expect the much more obvious ErrNoSuchEntity
. What gives?
This is on the local development server.
答案1
得分: 1
错误来自这里。根据"internal error"的提示,这听起来像是一个bug。阅读代码,似乎应该返回一个带有一个nil
Entity
字段的GetResponse_Entity
切片,但它要么返回太多的GetResponse_Entity
,要么一个都没有。
你可以在以下代码中进行调试:
go_appengine\goroot\src\pkg\appengine\datastore\datastore.go
在这部分代码中添加一些fmt.Println
:
req := &pb.GetRequest{
Key: multiKeyToProto(c.FullyQualifiedAppID(), key),
}
res := &pb.GetResponse{}
if err := c.Call("datastore_v3", "Get", req, res, nil); err != nil {
return err
}
或者尝试使用GDB进行调试(虽然我不确定如何调试app engine应用程序)。
你也可以尝试使用以下命令清除本地数据存储:
dev_appserver.py --clear_datastore=yes myapp
但这只是一种试探。
你可以尝试在邮件列表上提问,或许会有更好的运气。
英文:
The error is from here. Given the internal error
bit this sounds like a bug to me. Reading the code it seems like it should return a slice with one GetResponse_Entity
with a nil
Entity
field, but it's either returning too many GetResponse_Entity
s or none.
You could tinker with the source code in:
go_appengine\goroot\src\pkg\appengine\datastore\datastore.go
Add some fmt.Println
s to this part:
req := &pb.GetRequest{
Key: multiKeyToProto(c.FullyQualifiedAppID(), key),
}
res := &pb.GetResponse{}
if err := c.Call("datastore_v3", "Get", req, res, nil); err != nil {
return err
}
Or perhaps try debugging with GDB. (though I'm not sure how you debug an app engine app)
You could also try clearing your local data store with:
dev_appserver.py --clear_datastore=yes myapp
But that's just a shot in the dark.
You might have better luck asking on the mailing list.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论