dsrruefh12970 2018-06-02 00:32
浏览 41
已采纳

来自datastore.NewQuery(“”)。Ancestor(myKey)的“数据存储区:无效的实体类型”错误

I'm using the "cloud.google.com/go/datastore" library in my Go application (library version below), and am running into an error datastore: invalid entity type when I use the Ancestor() query.

Here's my method call:

ctx := context.Background()
client, err := datastore.NewClient(ctx, "MyProjectId", option.WithCredentialsFile(myJsonFile))
// ... err check ...
myId := 112233
myKey := datastore.IDKey("MyKind", myId, nil)

query := datastore.NewQuery("").Ancestor(myKey)    
it := client.Run(*ctx, query)
c = &struct{ ... }
key, err := it.Next(&c)
// ... err check ...

However, when I check the value of err, it's non-nil and has the message: datastore: invalid entity type. When I go into the cloud console and try what I think would be the equivalent GQL (e.g. SELECT * WHERE __key__ HAS ANCESTOR KEY(MyKind, 112233)), it does indeed return results in the cloud console.

I also didn't find a convenient way to print out debugging information in the "cloud.google.com/go/datastore" library to see what it's actually sending, so any help would be much appreciated there.

Any ideas on how I might debug this, or is it an issue in the Go library? Thank you!


P.S. Here's the "cloud.google.com/go/datastore" version I'm using:

commit f0afaf5fad3c46ae392ebab6b7553d37d65d07ac (HEAD -> master, origin/master, origin/HEAD)
Author: [redacted]
Date:   Thu May 31 13:15:30 2018 -0700

    oslogin: generate v1 client

    Change-Id: I515527be0e8acc1fe55cab969df9f76fd8d93b26
  • 写回答

1条回答 默认 最新

  • doumao6212 2018-06-02 05:28
    关注

    There's a bug in the code above which is passing a double reference to a struct.

    c = &struct{ ... }
    key, err := it.Next(&c)
    

    Should actually be:

    c = &struct{ ... }
    key, err := it.Next(c)
    

    Unfortunately the "Next" function returns a datastore: invalid entity type rather than something a little more... helpful ;)

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

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看