{"record":{"id":"565578459c04209f","repo":"apache/beam","slug":"unexpected-type-of-id-or-name-s","errorCode":null,"errorMessage":"Unexpected type of id_or_name: %s","messagePattern":"Unexpected type of id_or_name: (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/gcp/datastore/v1new/query_splitter.py","lineNumber":145,"sourceCode":"  return scatter_query\n\n\nclass IdOrName(object):\n  \"\"\"Represents an ID or name of a Datastore key,\n\n   Implements sort ordering: by ID, then by name, keys with IDs before those\n   with names.\n   \"\"\"\n  def __init__(self, id_or_name):\n    self.id_or_name = id_or_name\n    if isinstance(id_or_name, str):\n      self.id = None\n      self.name = id_or_name\n    elif isinstance(id_or_name, int):\n      self.id = id_or_name\n      self.name = None\n    else:\n      raise TypeError('Unexpected type of id_or_name: %s' % id_or_name)\n\n  def __lt__(self, other):\n    if not isinstance(other, IdOrName):\n      return super().__lt__(other)\n\n    if self.id is not None:\n      if other.id is None:\n        return True\n      else:\n        return self.id < other.id\n\n    if other.id is not None:\n      return False\n\n    return self.name < other.name\n\n  def __eq__(self, other):\n    if not isinstance(other, IdOrName):","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/gcp/datastore/v1new/query_splitter.py#L127-L163","documentation":"The IdOrName helper for Datastore keys accepts only a str (entity name) or an int (numeric auto-ID). Passing any other type makes it impossible to tell whether the value should populate the key's name or id field, so __init__ raises TypeError immediately.","triggerScenarios":"Constructing IdOrName with a value that is neither str nor int, e.g. IdOrName(12.5), IdOrName(None), IdOrName(b'abc'), or a key component built from an untyped config/JSON value.","commonSituations":"Datastore IDs read back from JSON or CSV arrive as strings that are actually numeric, or floats parsed from numeric columns; developers pass them straight into IdOrName without coercing to int.","solutions":["Convert the value: pass int(id_or_name) if it represents a numeric Datastore ID, or str(id_or_name) if it is a key name.","Check that upstream data (JSON, CSV, ValueProvider) yields the correct type and cast at the boundary.","For ambiguous numeric strings, decide explicitly whether they are IDs or names and wrap with int() or keep as str accordingly."],"exampleFix":"// before\nkey = Key(('Project', IdOrName(raw_id)))  # raw_id = '12345' from JSON\n// after\nkey = Key(('Project', IdOrName(int(raw_id))))  # numeric ID\n# or, if it is a name:\nkey = Key(('Project', IdOrName(str(raw_id))))","handlingStrategy":"type-guard","validationCode":"def to_id_or_name(v):\n    if isinstance(v, bool):\n        raise TypeError('bool is not a valid Datastore id_or_name')\n    if isinstance(v, int):\n        return IdOrName(v)\n    if isinstance(v, str):\n        return IdOrName(v)\n    raise TypeError(f'id_or_name must be str or int, got {type(v)}')","typeGuard":"def is_id_or_name(v):\n    return isinstance(v, (str, int)) and not isinstance(v, bool)","tryCatchPattern":"try:\n    component = IdOrName(raw)\nexcept TypeError as e:\n    component = IdOrName(str(raw))  # or int(raw) if numeric\n    logging.warning('Coerced id_or_name: %s', e)","preventionTips":["Cast IDs at the data-ingestion boundary (JSON/CSV)","Never pass bools, floats, or None into IdOrName","Decide explicitly whether a value is a key name or numeric ID"],"tags":["type-error","google-cloud-datastore","apache-beam"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}