{"record":{"id":"0e4afe95cdc68ac1","repo":"apache/beam","slug":"query-cannot-be-empty","errorCode":null,"errorMessage":"query cannot be empty","messagePattern":"query cannot be empty","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/gcp/datastore/v1new/datastoreio.py","lineNumber":128,"sourceCode":"  _DEFAULT_BUNDLE_SIZE_BYTES = 64 * 1024 * 1024\n\n  def __init__(self, query, num_splits=0):\n    \"\"\"Initialize the `ReadFromDatastore` transform.\n\n    This transform outputs elements of type\n    :class:`~apache_beam.io.gcp.datastore.v1new.types.Entity`.\n\n    Args:\n      query: (:class:`~apache_beam.io.gcp.datastore.v1new.types.Query`) query\n        used to fetch entities.\n      num_splits: (:class:`int`) (optional) Number of splits for the query.\n    \"\"\"\n    super().__init__()\n\n    if not query.project:\n      raise ValueError(\"query.project cannot be empty\")\n    if not query:\n      raise ValueError(\"query cannot be empty\")\n    if num_splits < 0:\n      raise ValueError(\"num_splits must be greater than or equal 0\")\n\n    self._project = query.project\n    # using _namespace conflicts with DisplayData._namespace\n    self._datastore_namespace = query.namespace\n    self._query = query\n    self._num_splits = num_splits\n\n  def expand(self, pcoll):\n    # This is a composite transform involves the following:\n    #   1. Create a singleton of the user provided `query` and apply a ``ParDo``\n    #   that splits the query into `num_splits` queries if possible.\n    #\n    #   If the value of `num_splits` is 0, the number of splits will be\n    #   computed dynamically based on the size of the data for the `query`.\n    #\n    #   2. The resulting ``PCollection`` is sharded across workers using a","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/gcp/datastore/v1new/datastoreio.py#L110-L146","documentation":"Raised by the argument-validation guard in ReadFromDatastore.__init__ (Datastore v1new source): after the helper checks that query.project is set, this generic empty-object guard rejects a falsy `query` argument — i.e. the caller passed None or an otherwise empty Query object instead of a fully-formed apache_beam.io.gcp.datastore.v1new.types.Query. The input at fault is the `query` parameter itself; construct a Query with a valid kind/project before passing it to the transform.","triggerScenarios":"Passing None in place of a query; constructing datastore.Query() with neither project nor kind set so it evaluates falsy (e.g. no kind attribute set); passing an empty placeholder query from config parsing.","commonSituations":"Pipeline templates where query parameters come from a config file that failed to populate; dynamically-built queries where all optional fields were omitted; typo passing the wrong variable (e.g. query=None).","solutions":["Ensure a fully populated Query (project and kind set) is passed to ReadFromDatastore.","Guard the construction site: raise/validate that the query has project and kind before building the transform.","Fix config loading so query fields are actually populated from the source configuration."],"exampleFix":"// before\nquery = None\nReadFromDatastore(query=query)  # ValueError: query cannot be empty\n\n// after\nquery = Query(project='my-gcp-project', kind='Person')\nReadFromDatastore(query=query)","handlingStrategy":"validation","validationCode":"if not query:\n    raise ValueError('query must be populated with project and kind')\nif not query.kind:\n    raise ValueError('query.kind must be set')","typeGuard":"def is_usable_query(query):\n    return bool(query) and bool(getattr(query, 'kind', None))","tryCatchPattern":"try:\n    read = ReadFromDatastore(query=query)\nexcept ValueError as e:\n    if 'query cannot be empty' in str(e):\n        query = build_query_from_config(cfg)  # re-derive the query\n        read = ReadFromDatastore(query=query)\n    else:\n        raise","preventionTips":["Check that config-driven query fields (project, kind) are populated before pipeline start.","Never pass None or a bare Query() placeholder to ReadFromDatastore.","Add an early assertion at pipeline construction with the intended kind."],"tags":["python","apache-beam","datastore","gcp","validation"],"backgroundTag":"empty-required-field","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}