{"record":{"id":"b1bc7b9c5a74a455","repo":"apache/beam","slug":"combineglobally-can-be-used-only-with-combinefn-objects","errorCode":null,"errorMessage":"CombineGlobally can be used only with combineFn objects. Received %r instead.","messagePattern":"CombineGlobally can be used only with combineFn objects\\. Received %r instead\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/core.py","lineNumber":2937,"sourceCode":"    ~apache_beam.pvalue.PCollection: A single-element\n    :class:`~apache_beam.pvalue.PCollection` containing the main output of\n    the :class:`CombineGlobally` transform.\n\n  Note that the positional and keyword arguments will be processed in order\n  to detect :class:`~apache_beam.pvalue.PValue` s that will be computed as side\n  inputs to the transform.\n  During pipeline execution whenever the :class:`CombineFn` object gets executed\n  (i.e. any of the :class:`CombineFn` methods get called), the\n  :class:`~apache_beam.pvalue.PValue` arguments will be replaced by their\n  actual value in the exact position where they appear in the argument lists.\n  \"\"\"\n  has_defaults = True\n  as_view = False\n  fanout = None  # type: typing.Optional[int]\n\n  def __init__(self, fn, *args, **kwargs):\n    if not (isinstance(fn, CombineFn) or callable(fn)):\n      raise TypeError(\n          'CombineGlobally can be used only with combineFn objects. '\n          'Received %r instead.' % (fn))\n\n    super().__init__()\n    self.fn = fn\n    self.args = args\n    self.kwargs = kwargs\n\n  def display_data(self):\n    return {\n        'combine_fn': DisplayDataItem(\n            self.fn.__class__, label='Combine Function'),\n        'combine_fn_dd': self.fn,\n    }\n\n  def default_label(self):\n    if self.fanout is None:\n      return '%s(%s)' % (","sourceCodeStart":2919,"sourceCodeEnd":2955,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/core.py#L2919-L2955","documentation":"CombineGlobally requires its fn argument to be either a CombineFn instance or a callable (which is then wrapped into a CombineFn). This TypeError fires when the argument is neither, guarding against passing random objects such as DoFns or partially-built transforms.","triggerScenarios":"Calling CombineGlobally(some_do_fn_or_object) where the object is not a CombineFn and has no __call__, e.g. passing a DoFn instance, a string, or a module.","commonSituations":"Copy-paste from a ParDo example into a combine step, or confusion between combine functions and DoFns when refactoring pipeline code.","solutions":["Pass a CombineFn subclass instance implementing create_accumulator/add_input/merge_accumulators/extract_output","Or pass a plain callable like sum or lambda xs: ... that takes an iterable","Verify the argument type before constructing: isinstance(fn, CombineFn) or callable(fn)"],"exampleFix":"// before\nbeam.CombineGlobally(MySumDoFn())\n// after\nbeam.CombineGlobally(sum)  # or a CombineFn subclass instance","handlingStrategy":"type-guard","validationCode":"if not (isinstance(fn, CombineFn) or callable(fn)):\n    raise TypeError('CombineGlobally requires a CombineFn or callable, got %r' % (fn,))","typeGuard":"def is_combinable(fn) -> bool:\n    return isinstance(fn, CombineFn) or callable(fn)","tryCatchPattern":"try:\n    step = beam.CombineGlobally(fn)\nexcept TypeError as e:\n    if 'CombineGlobally can be used only with combineFn' in str(e):\n        step = beam.CombineGlobally(wrap_into_combine_fn(fn))\n    else:\n        raise","preventionTips":["Use beam.CombineFn subclasses for complex aggregations","Do not pass DoFns to combine transforms; they belong to ParDo","Add unit tests constructing each transform with the intended argument type"],"tags":["python","apache-beam","combine","type-error"],"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"}