{"record":{"id":"919a2dd5823e749a","repo":"apache/beam","slug":"attempting-to-create-a-taggedoutput-with-non-string-tag-s","errorCode":null,"errorMessage":"Attempting to create a TaggedOutput with non-string tag %s","messagePattern":"Attempting to create a TaggedOutput with non-string tag (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/pvalue.py","lineNumber":341,"sourceCode":"    self._pcolls[tag] = pcoll\n    return pcoll\n\n\nTagType = TypeVar('TagType', bound=str)\nValueType = TypeVar('ValueType')\n\n\nclass TaggedOutput(Generic[TagType, ValueType]):\n  \"\"\"An object representing a tagged value.\n\n  ParDo, Map, and FlatMap transforms can emit values on multiple outputs which\n  are distinguished by string tags. The DoFn will return plain values\n  if it wants to emit on the main output and TaggedOutput objects\n  if it wants to emit a value on a specific tagged output.\n  \"\"\"\n  def __init__(self, tag: TagType, value: ValueType) -> None:\n    if not isinstance(tag, str):\n      raise TypeError(\n          'Attempting to create a TaggedOutput with non-string tag %s' %\n          (tag, ))\n    self.tag = tag\n    self.value = value\n\n\nclass AsSideInput(object):\n  \"\"\"Marker specifying that a PCollection will be used as a side input.\n\n  When a PCollection is supplied as a side input to a PTransform, it is\n  necessary to indicate how the PCollection should be made available\n  as a PTransform side argument (e.g. in the form of an iterable, mapping,\n  or single value).  This class is the superclass of all the various\n  options, and should not be instantiated directly. (See instead AsSingleton,\n  AsIter, etc.)\n  \"\"\"\n  def __init__(self, pcoll: PCollection) -> None:\n    from apache_beam.transforms import sideinputs","sourceCodeStart":323,"sourceCodeEnd":359,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/pvalue.py#L323-L359","documentation":"TaggedOutput.__init__ is a type guard on the tag argument: tagged outputs are keyed by string tags in ParDo/Map, so a non-string tag (int, tuple, etc.) would break output dispatch and is rejected at construction.","triggerScenarios":"Returning beam.TaggedOutput(1, value) from a DoFn; using an enum or int constant as a tag; passing a None tag.","commonSituations":"DoFns emitting side outputs with numeric channel ids converted from other systems; refactors replacing string tags with enum values.","solutions":["Convert the tag with str(tag) before constructing TaggedOutput","Use consistent string constants for side-output tags","Apply the tag via beam.pvalue.TaggedOutput(str(tag), value) or beam.tag_output(str(tag), value)"],"exampleFix":"// before\nyield beam.pvalue.TaggedOutput(0, element)\n// after\nyield beam.pvalue.TaggedOutput('even', element)","handlingStrategy":"validation","validationCode":"if not isinstance(tag, str):\n    raise ValueError('Side-output tag must be a string')","typeGuard":"def is_valid_tag(tag):\n    return isinstance(tag, str)\n","tryCatchPattern":"try:\n    out = beam.pvalue.TaggedOutput(tag, value)\nexcept TypeError as e:\n    out = beam.pvalue.TaggedOutput(str(tag), value)","preventionTips":["Coerce numeric tags with str() before creating TaggedOutput","Avoid enum/int constants for side-output tags","Add a lint/test asserting all tags emitted by DoFns are strings"],"tags":["python","apache-beam","side-outputs","argument-type"],"backgroundTag":"invalid-argument-format","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"}