apache/beam · error · TypeError
@yields_elements must be applied to a process or process_bat
Error message
@yields_elements must be applied to a process or process_batch method, got {fn!r}. What it means
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.
Source
Thrown at sdks/python/apache_beam/transforms/core.py:672
"""A decorator on process fn specifying that the fn performs an unbounded
amount of work per input element."""
def wrapper(process_fn):
process_fn.unbounded_per_element = True
return process_fn
return wrapper
@staticmethod
def yields_elements(fn):
"""A decorator to apply to ``process_batch`` indicating it yields elements.
By default ``process_batch`` is assumed to both consume and produce
"batches", which are collections of multiple logical Beam elements. This
decorator indicates that ``process_batch`` **produces** individual elements
at a time. ``process_batch`` is always expected to consume batches.
"""
if not fn.__name__ in ('process', 'process_batch'):
raise TypeError(
"@yields_elements must be applied to a process or "
f"process_batch method, got {fn!r}.")
fn._beam_yields_elements = True
return fn
@staticmethod
def yields_batches(fn):
"""A decorator to apply to ``process`` indicating it yields batches.
By default ``process`` is assumed to both consume and produce
individual elements at a time. This decorator indicates that ``process``
**produces** "batches", which are collections of multiple logical Beam
elements.
"""
if not fn.__name__ in ('process', 'process_batch'):
raise TypeError(
"@yields_elements must be applied to a process or "View on GitHub (pinned to 12126d8942)
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.
Example fix
# before
class MyDoFn(DoFn):
@yields_elements
def expand(self, batch):
yield from batch
# after
class MyDoFn(DoFn):
@yields_elements
def process_batch(self, batch):
yield from batch Defensive patterns
Strategy: validation
Validate before calling
def check_yields_elements(fn):
if fn.__name__ not in ('process', 'process_batch'):
raise TypeError(f'@yields_elements must decorate process/process_batch, got {fn.__name__}')
return fn Type guard
def is_batch_method(fn) -> bool:
return callable(fn) and getattr(fn, '__name__', None) in ('process', 'process_batch') Try / catch
try:
yields_elements(my_method)
except TypeError as e:
if 'process or process_batch' in str(e):
raise ValueError(f'Rename {my_method.__name__} to process or process_batch') from e
raise Prevention
- 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
When it happens
Trigger: Decorating a method with any other name, e.g. @yields_elements def expand(...) or @yields_elements def run(...), inside a DoFn.
Common situations: Typo in the method name (e.g. `proces`), applying the decorator to a helper or classmethod, copy-pasting the decorator above the wrong method.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- text_splitter must be a LangChain TextSplitter
- A context manager constructor (not a fully constructed conte
- DoFn {self!r} yields element from both process and process_b
- Either {self.__class__.__name__}.process_batch() must have a
- DoFn {self!r} yields batches from both process and process_b
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/c3241da1c1a54674.
Report an issue: GitHub.