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 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?