{"record":{"id":"2798764879b4e3dc","repo":"apache/beam","slug":"combine-fn-must-be-specified","errorCode":null,"errorMessage":"combine_fn must be specified.","messagePattern":"combine_fn must be specified\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/trigger.py","lineNumber":113,"sourceCode":"  \"\"\"StateTag pointing to an element.\"\"\"\n  def __repr__(self):\n    return 'SetStateTag({tag})'.format(tag=self.tag)\n\n  def with_prefix(self, prefix):\n    return _SetStateTag(prefix + self.tag)\n\n\nclass _CombiningValueStateTag(_StateTag):\n  \"\"\"StateTag pointing to an element, accumulated with a combiner.\n\n  The given tag must be unique for this step. The given CombineFn will be\n  applied (possibly incrementally and eagerly) when adding elements.\"\"\"\n\n  # TODO(robertwb): Also store the coder (perhaps extracted from the combine_fn)\n  def __init__(self, tag, combine_fn):\n    super().__init__(tag)\n    if not combine_fn:\n      raise ValueError('combine_fn must be specified.')\n    if not isinstance(combine_fn, core.CombineFn):\n      combine_fn = core.CombineFn.from_callable(combine_fn)\n    self.combine_fn = combine_fn\n\n  def __repr__(self):\n    return 'CombiningValueStateTag(%s, %s)' % (self.tag, self.combine_fn)\n\n  def with_prefix(self, prefix):\n    return _CombiningValueStateTag(prefix + self.tag, self.combine_fn)\n\n  def without_extraction(self):\n    class NoExtractionCombineFn(core.CombineFn):\n      setup = self.combine_fn.setup\n      create_accumulator = self.combine_fn.create_accumulator\n      add_input = self.combine_fn.add_input\n      merge_accumulators = self.combine_fn.merge_accumulators\n      compact = self.combine_fn.compact\n      extract_output = staticmethod(lambda x: x)","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/trigger.py#L95-L131","documentation":"_CombiningValueStateTag.__init__ requires a combine_fn and raises ValueError when it is missing, None, or otherwise falsy. The tag is a trigger-state holder keyed by a CombineFn, so without one the state cannot accumulate or merge values.","triggerScenarios":"Constructing _CombiningValueStateTag('mytag', None) or with an omitted second argument; also triggered by passing a falsy object (e.g. an empty container) as combine_fn.","commonSituations":"Custom trigger/state code inside Beam's trigger driver internals; tests that build state tags manually and forget the combiner; refactors that renamed a combine_fn variable leaving it undefined/None.","solutions":["Pass a CombineFn instance, e.g. combiners.CountCombineFn() or SumCombineFn(), as the second argument.","A plain callable is accepted too: it is wrapped via CombineFn.from_callable, so pass the function rather than None.","Check that the variable holding the combiner is actually defined at the call site (not shadowed or set to None)."],"exampleFix":"// before\ntag = _CombiningValueStateTag('sum')\n// after\ntag = _CombiningValueStateTag('sum', combiners.SumCombineFn())","handlingStrategy":"validation","validationCode":"assert combine_fn is not None, 'combine_fn is required for _CombiningValueStateTag'","typeGuard":"def has_combine_fn(fn):\n    return bool(fn) and (isinstance(fn, core.CombineFn) or callable(fn))","tryCatchPattern":"try:\n    tag = _CombiningValueStateTag(name, combine_fn)\nexcept ValueError:\n    tag = _CombiningValueStateTag(name, core.CombineFn.from_callable(sum))","preventionTips":["Always pass a CombineFn (or callable) when constructing state tags.","Keep combine_fn definitions near tag construction to avoid None from refactors.","Add constructor assertions in custom trigger tests."],"tags":["python","apache-beam","trigger","combinefn","valueerror"],"backgroundTag":"missing-required-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-15T13:17:12.816Z"}