{"record":{"id":"ffe7b03eab1437ae","repo":"apache/beam","slug":"apache-beam-io-gcp-datastore-v1new-datastoreio-key-expected","errorCode":null,"errorMessage":"apache_beam.io.gcp.datastore.v1new.datastoreio.Key expected, got: %s","messagePattern":"apache_beam\\.io\\.gcp\\.datastore\\.v1new\\.datastoreio\\.Key expected, got: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/gcp/datastore/v1new/datastoreio.py","lineNumber":591,"sourceCode":"      project,\n      throttle_rampup=True,\n      hint_num_workers=_Mutate._DEFAULT_HINT_NUM_WORKERS):\n    \"\"\"Initialize the `DeleteFromDatastore` transform.\n\n    Args:\n      project: (:class:`str`) The ID of the project from which the entities will\n        be deleted.\n      throttle_rampup: Whether to enforce a gradual ramp-up.\n      hint_num_workers: A hint for the expected number of workers, used to\n                        estimate appropriate limits during ramp-up throttling.\n    \"\"\"\n    mutate_fn = DeleteFromDatastore._DatastoreDeleteFn(project)\n    super().__init__(mutate_fn, throttle_rampup, hint_num_workers)\n\n  class _DatastoreDeleteFn(_Mutate.DatastoreMutateFn):\n    def element_to_client_batch_item(self, element):\n      if not isinstance(element, types.Key):\n        raise ValueError(\n            'apache_beam.io.gcp.datastore.v1new.datastoreio.Key'\n            ' expected, got: %s' % type(element))\n      if not element.project:\n        element.project = self._project\n      client_key = element.to_client_key()\n      if client_key.is_partial:\n        raise ValueError(\n            'Keys to be deleted from Cloud Datastore must be '\n            'complete:\\n%s' % client_key)\n      return client_key\n\n    def add_to_batch(self, client_key):\n      self._batch.delete(client_key)\n\n    def display_data(self):\n      return {\n          'mutation': 'Delete',\n          'project': self._project,","sourceCodeStart":573,"sourceCodeEnd":609,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/gcp/datastore/v1new/datastoreio.py#L573-L609","documentation":"DeleteFromDatastore's _DatastoreDeleteFn only accepts apache_beam.io.gcp.datastore.v1new.types.Key elements; any other element type raises ValueError identifying the actual received type. The check runs before converting to a client key.","triggerScenarios":"Piping Entities, dicts, strings, or google.datastore.v1 Keys into DeleteFromDatastore; feeding output of a source that yields entity payloads instead of just keys; using v1-era key types with the v1new sink.","commonSituations":"Wanting to delete whole entities from a read pipeline (must project out keys first); mixing datastore v1 and v1new APIs; passing key tuples like (kind, id) directly.","solutions":["Map each element to apache_beam.io.gcp.datastore.v1new.types.Key before DeleteFromDatastore.","If you have Entities, use element.key to extract the v1new Key.","If you have (kind, id) pairs, construct types.Key(kind, id, project=project) in a Map step.","Verify imports come from datastore.v1new.types, not the legacy v1 package."],"exampleFix":"// before\n| 'delete' >> DeleteFromDatastore(project)   # elements are dicts\n// after\n| 'to_key' >> beam.Map(lambda d: types.Key(d['kind'], d['id'], project=project)) \\\n| 'delete' >> DeleteFromDatastore(project)","handlingStrategy":"type-guard","validationCode":"from apache_beam.io.gcp.datastore.v1new import types\nassert all(isinstance(k, types.Key) for k in elements), 'non-Key element for DeleteFromDatastore'","typeGuard":"def is_deletable_key(e):\n    from apache_beam.io.gcp.datastore.v1new import types\n    return isinstance(e, types.Key)","tryCatchPattern":"try:\n    _ = pcoll | DeleteFromDatastore(project)\nexcept ValueError as e:\n    if 'Key expected' in str(e):\n        pcoll = pcoll | beam.Map(lambda e: e.key if isinstance(e, types.Entity) else to_key(e))\n        _ = pcoll | DeleteFromDatastore(project)","preventionTips":["Project out keys (entity.key) before deleting from a read pipeline","Construct keys with types.Key(kind, id, project=project)","Do not pass tuples, dicts, or v1 key objects to the v1new sink","Type-hint the PCollection as types.Key before the sink"],"tags":["python","type-mismatch","beam-io","datastore"],"backgroundTag":"type-mismatch","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}