google-app-engine - Go 中奇怪的数据存储错误, "The kind is the empty string"

标签 google-app-engine go google-cloud-datastore

我最近在发出简单的 datastore.GetAll() 请求时遇到了以前从未见过的错误。我不明白这是什么意思,也找不到任何包含错误消息的文档或 Google 搜索错误消息的任何帮助。

这是我的代码:

type MyUnderlyingStruct struct {
    ApplyTo             *datastore.Key
    ApplyFrom           *datastore.Key
    Amount              float64
    LocationKey         *datastore.Key
    DepartmentKey       *datastore.Key
    SubjectAreaKey      *datastore.Key
}

type MyStruct []MyUnderlyingStruct 

//In the case where I get the error someKey is a valid, complete Key value
//  of a different kind that what we are querying for and there is actually
//  an entity in my datastore that matches this query
func (x *MyStruct) Load(w http.ResponseWriter, r *http.Request, someKey *datastore.Key) (error) {
    c := appengine.NewContext(r)
    q := datastore.NewQuery("MyUnderlyingStruct_KindName").Order("-Amount")
    if someKey != nil { q = q.Filter("ApplyTo=", someKey) }

    keys, err := q.GetAll(c,x)
    if _, ok := err.(*datastore.ErrFieldMismatch); ok { err = nil }
    if err != nil && err != datastore.Done {return err}
    return nil
}

返回此错误:

API error 1 (datastore_v3: BAD_REQUEST): The kind is the empty string.

谁能告诉我为什么会出现这个错误,或者它想告诉我什么?

最佳答案

乍一看您的问题(因为我不熟悉 Google 的数据存储 API),在我看来问题是使用 new 关键字进行清零内存初始化的结果。

当使用关键字创建结构时没有为字段分配起始值,默认值为 0。当映射到字符串时,它是“”(空)。 Go 实际上为您抛出了一个非常有用的错误。

正如您所指出的,您使用了 Mykey := new(datastore.Key)。感谢您的慷慨,这可以作为 future 用户的答案。

关于google-app-engine - Go 中奇怪的数据存储错误, "The kind is the empty string",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28220714/

相关文章:

python - 使用 pandas 和 Google App Engine 时出现 AttributeError

image-processing - 去调整图像大小

java - 对于 Google App Engine (java),如何在 FetchOptions 中设置和使用 block 大小?

python - Webapp2返回状态码418的方法

java - GAE + Spring MVC : Saving image file to BlobStore

java - 如何仅处理谷歌应用程序引擎中特定请求路径的并发?

java - GAE DataStore 复合索引无法工作/无法识别

postgresql - 运行 postgres 查询时出现无效内存地址错误

go - 对于常量表达式和其他表达式,Go编译器的评估是否有所不同

java - 错误 :The import com. google.appengine.api.datastore 无法解析 JPA GAE GWT