dso0139 2015-01-29 17:18
浏览 31
已采纳

Go中出现奇怪的数据存储错误,“种类是空字符串”

I am recently getting an error that I have never seen before when making a simple datastore.GetAll() request. I can't figure out what it means and I can't find any documentation with the error message or any help from Googleing the error message.

Here's my code:

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
}

Which returns this error:

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

Can anyone tell me why I am getting this error, or what it is trying to tell me?

  • 写回答

1条回答 默认 最新

  • dsp1836 2015-02-03 01:24
    关注

    Looking at your issue on the first glance (because I am not familiar with Google's datastore API), it seems to me the problem is a result of zeroed-memory initialization using new keyword.

    When a struct is created with the keyword without assigning starting values for the fields, 0's are given as default. When mapped to string, it's "" (empty). Go actually threw a very helpful error for you.

    As you have pointed out, you have used Mykey := new(datastore.Key). Thanks for your generosity and this can serve as answer for future users.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan