dongsha9208 2014-01-13 19:31
浏览 25
已采纳

AppEngine的datastore.Get()是否不验证所请求键的名称空间?

I'm using namespaces with the datastore in go-appengine, roughly as follows:

func getThing() *Thing {
  nctx := appengine.Namespace(ctx, "whatever")

  thing := Thing{}
  key, err := datastore.Get(nctx, key, &thing)
  if err != nil {
    return nil, err
  }
  return thing, nil
}

Simple enough, right? Unfortunately, if it turns out that if nctx's namespace doesn't match the key's, it happily fetches the object anyway. And AFAICT, there's no way to manually get at the key's 'namespace' field to verify it manually. This matters for our app, because we have keys coming from a web client, which can in some edge cases be associated with the wrong namespace.

OTOH, if I do a query using Thing's key as an ancestor, the datastore (appropriately) returns an error because of the namespace mismatch between the ancestor's namespace and that of the context (of the form query namespace is 'bar' but ancestor namespace is 'foo').

Am I missing something about the intended constraints on datastore fetches/queries and namespaces, or does this just sound like a bug?

  • 写回答

1条回答 默认 最新

  • dqysi86208 2014-01-13 20:53
    关注

    I assume you're passing around encoded keys, rather than just their IDs? If you create the key using datastore.NewKey then the context passed to that will set the namespace of the key (unless there's also a parent, in which case its namespace will be used).

    With respect to the intention, this behaviour is equivalent to the python API - a key created from an urlsafe string can be fetched while a different namespace is set on the namespace_mananger, but the currently-set namespace is used if you create a key by specifying just the kind and id.

    Having a getter for the namespace would be good though, so you could at least verify after unserializing...

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

报告相同问题?

悬赏问题

  • ¥15 爬取1-112页所有帖子的标题但是12页后要登录后才能 我使用selenium模拟登录 账号密码输入后 会报错 不知道怎么弄了
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点