{"record":{"id":"c3241da1c1a54674","repo":"apache/beam","slug":"yields-elements-must-be-applied-to-a-process-or-process","errorCode":null,"errorMessage":"@yields_elements must be applied to a process or process_batch method, got {fn!r}.","messagePattern":"@yields_elements must be applied to a process or process_batch method, got (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/core.py","lineNumber":672,"sourceCode":"    \"\"\"A decorator on process fn specifying that the fn performs an unbounded\n    amount of work per input element.\"\"\"\n    def wrapper(process_fn):\n      process_fn.unbounded_per_element = True\n      return process_fn\n\n    return wrapper\n\n  @staticmethod\n  def yields_elements(fn):\n    \"\"\"A decorator to apply to ``process_batch`` indicating it yields elements.\n\n    By default ``process_batch`` is assumed to both consume and produce\n    \"batches\", which are collections of multiple logical Beam elements. This\n    decorator indicates that ``process_batch`` **produces** individual elements\n    at a time. ``process_batch`` is always expected to consume batches.\n    \"\"\"\n    if not fn.__name__ in ('process', 'process_batch'):\n      raise TypeError(\n          \"@yields_elements must be applied to a process or \"\n          f\"process_batch method, got {fn!r}.\")\n\n    fn._beam_yields_elements = True\n    return fn\n\n  @staticmethod\n  def yields_batches(fn):\n    \"\"\"A decorator to apply to ``process`` indicating it yields batches.\n\n    By default ``process`` is assumed to both consume and produce\n    individual elements at a time. This decorator indicates that ``process``\n    **produces** \"batches\", which are collections of multiple logical Beam\n    elements.\n    \"\"\"\n    if not fn.__name__ in ('process', 'process_batch'):\n      raise TypeError(\n          \"@yields_elements must be applied to a process or \"","sourceCodeStart":654,"sourceCodeEnd":690,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/core.py#L654-L690","documentation":"The @yields_elements decorator (core.py:672) marks a method as producing individual elements from a batch. It validates that the decorated method is named `process` or `process_batch`, since those are the only methods whose batching semantics Beam understands; applying it anywhere else is a programming mistake.","triggerScenarios":"Decorating a method with any other name, e.g. @yields_elements def expand(...) or @yields_elements def run(...), inside a DoFn.","commonSituations":"Typo in the method name (e.g. `proces`), applying the decorator to a helper or classmethod, copy-pasting the decorator above the wrong method.","solutions":["Rename the decorated method to `process` or `process_batch`.","Remove @yields_elements from methods that are not `process`/`process_batch`.","If you need element-level yields from a differently-named method, move the logic into `process` and call the helper from there."],"exampleFix":"# before\nclass MyDoFn(DoFn):\n    @yields_elements\n    def expand(self, batch):\n        yield from batch\n\n# after\nclass MyDoFn(DoFn):\n    @yields_elements\n    def process_batch(self, batch):\n        yield from batch","handlingStrategy":"validation","validationCode":"def check_yields_elements(fn):\n    if fn.__name__ not in ('process', 'process_batch'):\n        raise TypeError(f'@yields_elements must decorate process/process_batch, got {fn.__name__}')\n    return fn","typeGuard":"def is_batch_method(fn) -> bool:\n    return callable(fn) and getattr(fn, '__name__', None) in ('process', 'process_batch')","tryCatchPattern":"try:\n    yields_elements(my_method)\nexcept TypeError as e:\n    if 'process or process_batch' in str(e):\n        raise ValueError(f'Rename {my_method.__name__} to process or process_batch') from e\n    raise","preventionTips":["Only apply @yields_elements directly above a method literally named process or process_batch","Run type checks / doctest imports at module load to catch decorator misuse before pipeline launch","Avoid stacking batching decorators on helper methods"],"tags":["python","apache-beam","decorator","typeerror"],"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"}