{"record":{"id":"d02643b7c7930571","repo":"apache/beam","slug":"invalid-tag","errorCode":null,"errorMessage":"Invalid tag.","messagePattern":"Invalid tag\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/trigger.py","lineNumber":1164,"sourceCode":"      original_tag, tag = tag, tag.without_extraction()\n    values = [\n        self.raw_state.get_state(window_id, tag)\n        for window_id in self._get_ids(window)\n    ]\n    if isinstance(tag, _ReadModifyWriteStateTag):\n      raise ValueError(\n          'Merging requested for non-mergeable state tag: %r.' % tag)\n    elif isinstance(tag, _CombiningValueStateTag):\n      return original_tag.combine_fn.extract_output(\n          original_tag.combine_fn.merge_accumulators(values))\n    elif isinstance(tag, _ListStateTag):\n      return [v for vs in values for v in vs]\n    elif isinstance(tag, _SetStateTag):\n      return {v for vs in values for v in vs}\n    elif isinstance(tag, _WatermarkHoldStateTag):\n      return tag.timestamp_combiner_impl.combine_all(values)\n    else:\n      raise ValueError('Invalid tag.', tag)\n\n  def clear_state(self, window, tag):\n    for window_id in self._get_ids(window):\n      self.raw_state.clear_state(window_id, tag)\n    if tag is None:\n      del self.window_ids[window]\n      self._persist_window_ids()\n\n  def merge(self, to_be_merged, merge_result):\n    for window in to_be_merged:\n      if window != merge_result:\n        if window in self.window_ids:\n          if merge_result in self.window_ids:\n            merge_window_ids = self.window_ids[merge_result]\n          else:\n            merge_window_ids = self.window_ids[merge_result] = []\n          merge_window_ids.extend(self.window_ids.pop(window))\n          self._persist_window_ids()","sourceCodeStart":1146,"sourceCodeEnd":1182,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/trigger.py#L1146-L1182","documentation":"MergingTriggerState.get_state falls through to ValueError('Invalid tag.', tag) when the tag is none of the recognized mergeable types (_CombiningValueStateTag, _ListStateTag, _SetStateTag, _WatermarkHoldStateTag, and not an RMW tag caught earlier). It guards against unknown or corrupted tag objects reaching the merge path.","triggerScenarios":"Calling merging get_state with a custom/foreign state-tag object that subclasses none of the supported tag types, or a tag instance whose class hierarchy was changed between Beam versions.","commonSituations":"Custom state tags defined by user trigger extensions; code upgraded across Beam versions where tag classes were renamed or restructured; deserialized/pickled tag objects of the wrong type.","solutions":["Use one of the supported tag types: _CombiningValueStateTag, _ListStateTag, _SetStateTag, or _WatermarkHoldStateTag.","Inspect the tag passed in (it appears in the exception args) and fix its construction site.","Check for Beam version drift: a tag class that was supported may no longer be; update the tag to the current API."],"exampleFix":"// before\nclass MyTag: pass\nstate.get_state(window, MyTag())  # ValueError: Invalid tag\n// after\ntag = _ListStateTag('items')\nstate.get_state(window, tag)","handlingStrategy":"type-guard","validationCode":"from apache_beam.transforms import trigger as t\nif not isinstance(tag, (t._CombiningValueStateTag, t._ListStateTag, t._SetStateTag, t._WatermarkHoldStateTag)):\n    raise TypeError(f'Unsupported state tag type: {type(tag)}')","typeGuard":"def is_supported_merge_tag(tag):\n    from apache_beam.transforms import trigger as t\n    return isinstance(tag, (t._CombiningValueStateTag, t._ListStateTag, t._SetStateTag, t._WatermarkHoldStateTag))","tryCatchPattern":"try:\n    value = state.get_state(window, tag)\nexcept ValueError as e:\n    logger.error('Bad tag %r: %s', tag, e)\n    raise","preventionTips":["Only construct tags from Beam's own tag classes; avoid custom subclasses.","Check the tag printed in the exception args to locate the bad construction site.","Re-verify tag classes after Beam upgrades."],"tags":["python","apache-beam","trigger","state","valueerror"],"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-14T16:17:12.679Z"}