{"record":{"id":"75d148ff8c26292e","repo":"apache/beam","slug":"unknown-annotation-type-r-type-s-for-s","errorCode":null,"errorMessage":"Unknown annotation type %r (type %s) for %s","messagePattern":"Unknown annotation type %r \\(type (.+?)\\) for (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/pipeline.py","lineNumber":1635,"sourceCode":"    if self.resource_hints:\n      for part in self.parts:\n        part._merge_outer_resource_hints()\n\n\ndef encode_annotations(annotations: Optional[dict[str, Any]]):\n  \"\"\"Encodes non-byte annotation values as bytes.\"\"\"\n  if not annotations:\n    return {}\n\n  def annotation_to_bytes(key, a: Any) -> bytes:\n    if isinstance(a, bytes):\n      return a\n    elif isinstance(a, str):\n      return a.encode('ascii')\n    elif isinstance(a, message.Message):\n      return a.SerializeToString()\n    else:\n      raise TypeError(\n          'Unknown annotation type %r (type %s) for %s' % (a, type(a), key))\n\n  return {key: annotation_to_bytes(key, a) for (key, a) in annotations.items()}\n\n\n_global_annotations_stack_data = threading.local()\n\n\ndef _global_annotations_stack():\n  try:\n    return _global_annotations_stack_data.stack\n  except AttributeError:\n    _global_annotations_stack_data.stack = [{}]\n    return _global_annotations_stack_data.stack\n\n\n@contextlib.contextmanager\ndef transform_annotations(**annotations):","sourceCodeStart":1617,"sourceCodeEnd":1653,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/pipeline.py#L1617-L1653","documentation":"TypeError raised in encode_annotations' annotation_to_bytes helper when an annotation value is not bytes, an ascii-encodable str, or a protobuf Message. Pipeline annotations must be serializable to bytes for the runner-api proto.","triggerScenarios":"Setting pipeline/transform annotations (via annotations param or with_annotations) to dict/int/list objects instead of str, bytes, or protobuf Message.","commonSituations":"Attaching structured metadata (JSON dicts, numbers) to pipeline annotations for custom runners; passing numpy values.","solutions":["Convert the annotation value to a str or bytes before attaching (e.g. json.dumps(payload))","Use a protobuf message if you need structured annotations","Serialize custom objects to bytes yourself (with an agreed encoding on the consumer side)"],"exampleFix":"// before\npipeline.annotations['meta'] = {'owner': 'team'}\n// after\nimport json\npipeline.annotations['meta'] = json.dumps({'owner': 'team'})","handlingStrategy":"validation","validationCode":"from google.protobuf.message import Message\nfor k, v in annotations.items():\n    assert isinstance(v, (bytes, str, Message)), f'Bad annotation {k}: {type(v)}'","typeGuard":"from google.protobuf.message import Message\n\ndef is_valid_annotation(v):\n    return isinstance(v, (bytes, str, Message))","tryCatchPattern":"try:\n    encoded = pipeline.annotations\nexcept TypeError as e:\n    logging.error('Unsupported annotation type: %s', e)","preventionTips":["Store annotations only as str, bytes, or protobuf Messages","Use json.dumps for structured metadata","Document the annotation schema for custom runner consumers"],"tags":["python","apache-beam","annotations","argument-type"],"backgroundTag":"unsupported-dtype","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"}