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 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染