数据存储查询删除类型错误:无法通过项目

问题描述 投票:0回答:1

我想查询几个GCP项目中的DataSotre服务来收集聚合实体。 为了实现这一目标,我正在使用以下内容对我的暂存环境进行测试:

from_cases_query = client.query(kind="Case",project="staging").add_filter("createdDate", ">=", start_date) 

但是在运行之后我得到:

File "/usr/local/lib/python3.9/dist-packages/google/cloud/datastore/client.py", line 836, in query
    raise TypeError("Cannot pass project")
TypeError: Cannot pass project

为什么会这样?

Google 文档在这里:https://cloud.google.com/python/docs/reference/datastore/latest/queries#class-googleclouddatastorequeryqueryclient-kindnone-projectnone-namespacenone-ancestornone-filters-projection-order-distincton

  • 语法不同
  • 删除了 client.query 中的项目参数 - 有效
google-cloud-platform google-cloud-datastore datastore
1个回答
0
投票
  1. 您的代码与您引用的链接中的定义不同。

    您的代码正在使用客户端运行查询,即

    client.query()
    而您引用的链接直接使用数据存储库,因此它传递了一个客户端和一个项目,即
    google.cloud.datastore.query.Query(client, kind=None, project=None

  2. 要做你想做的事,你必须使用链接文档中的代码,即类似于

    from google.cloud import datastore
    my_client = datastore.Client() 
    
    datastore.query.Query(my_client, kind=None, project=None, 
       namespace=None, ancestor=None, filters=(), 
        projection=(), order=(), distinct_on=())
    
    
© www.soinside.com 2019 - 2024. All rights reserved.