google-cloud-platformgoogle-cloud-datastoredatastore

Datastore query dropping TypeError: Cannot pass project


I want to query DataSotre services in several GCP projects to collect aggregated entities. To achive so, I am testing with my staging environment with the following:

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

But after running I am getting:

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

Why is this happening?

Google documentation here: https://cloud.google.com/python/docs/reference/datastore/latest/queries#class-googleclouddatastorequeryqueryclient-kindnone-projectnone-namespacenone-ancestornone-filters-projection-order-distincton


Solution

    1. Your code is different from the definition in the link you referenced.

      Your code is running the query using a client i.e. client.query() whereas the link you referenced is using the datastore library directly and so it passes a client and a project i.e. google.cloud.datastore.query.Query(client, kind=None, project=None

    2. To do what you want, you have to use the code from your linked documentation i.e. something along the lines of

      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=())