"datastore: internal error: server returned the wrong number of entities" when retrieving non-existent object

huangapple go评论76阅读模式
英文:

"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_Entitys or none.

You could tinker with the source code in:

go_appengine\goroot\src\pkg\appengine\datastore\datastore.go

Add some fmt.Printlns 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.

huangapple
  • 本文由 发表于 2013年12月28日 02:25:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/20805821.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定