gpt4 book ai didi

google-app-engine - "datastore: internal error: server returned the wrong number of entities"检索不存在的对象时

转载 作者:IT王子 更新时间:2023-10-29 01:46:21 25 4
gpt4 key购买 nike

使用 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 // Some random type

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。给了什么?

这是在本地开发服务器上。

最佳答案

错误来自here .考虑到 internal error 位,这对我来说听起来像是一个错误。阅读代码似乎它应该返回一个带有 nil Entity 字段的 GetResponse_Entity slice ,但它要么返回太多 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 进行调试。 (尽管我不确定您如何调试应用引擎应用)

您还可以尝试使用以下方法清除本地数据存储:

dev_appserver.py --clear_datastore=yes myapp

但这只是瞎猜。

mailing list 上提问可能运气会更好.

关于google-app-engine - "datastore: internal error: server returned the wrong number of entities"检索不存在的对象时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20805821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com