英文:
Getting weird error on datastore.Query.Run(c).Next(x)
问题
我以前从未遇到过这个特定的错误,当我在谷歌上搜索时,根本找不到任何提到它的内容。我正在使用Go语言,执行一个标准的数据存储查询,就像我以前多次使用迭代器一样,但是我得到了这个错误:"proto: required fields not set in datastore.QueryResult"。请看下面的代码,有什么想法吗?
k, err := datastore.NewQuery("QBConnection").
Ancestor(datastore.NewKey(c, "Company", "", x.CompanyID, nil)).
Limit(1).
Run(c).
Next(x)
if err != nil {
if _, ok := err.(*datastore.ErrFieldMismatch); ok { err = nil } //如果无法加载某些字段,则忽略它
if err == datastore.Done { err = nil } //如果在数据存储中找不到,则只返回nil
if err != nil {return err}
}
英文:
I have not run into this particular error before, and when I Google it I can't find anything at all out there that even mentions it. I am using Go language, performing a standard datastore query like I have many times before using an iterator, and I get this error: "proto: required fields not set in datastore.QueryResult". See my code below, any ideas?
k, err := datastore.NewQuery("QBConnection").
Ancestor(datastore.NewKey(c, "Company", "", x.CompanyID, nil)).
Limit(1).
Run(c).
Next(x)
if err != nil {
if _, ok := err.(*datastore.ErrFieldMismatch); ok { err = nil } //ignore it if we can't load some fields
if err == datastore.Done { err = nil } //If we don't find it in datastore, then just return nil
if err != nil {return err}
}
答案1
得分: 3
我至少为我的情况找到了解决方法。我仍然不确定错误消息的确切含义,当我在实际环境中运行时,我得到了不同的错误(这导致了我的答案)。在实际网站上,它告诉我“缺少祖先的id/名称”...长话短说,我的x.CompanyID变量在运行查询之前没有正确设置。不确定为什么开发/实际环境的错误消息如此不同,如果在我的开发服务器上能得到缺少的id/名称错误将会很有帮助...但是无论如何,问题已解决。
英文:
I figure it out for my case, at least. I'm still unsure exactly what the error message is supposed to mean, and I got a different error when I ran this in the live environment (which led to my answer). On the live site it told me "ancestor missing id/name"... long story short, my x.CompanyID variable was not set properly before running the query. Not sure why the error messages were so different on dev/live, and sure would have helped to get the missing id/name error on my dev server... but oh well, problem solved.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论