apache/beam · error · ValueError

window_coder should not be None

Error message

window_coder should not be None

What it means

The _ReassignWindowsDoFn's window-coder wrapper requires a coders.Coder for windows; constructing it with window_coder=None raises ValueError because windowing assignment cannot serialize/identify windows without a coder.

Source

Thrown at sdks/python/apache_beam/transforms/util.py:1437

class _IdentityWindowFn(NonMergingWindowFn):
  """Windowing function that preserves existing windows.

  To be used internally with the Reshuffle transform.
  Will raise an exception when used after DoFns that return TimestampedValue
  elements.
  """
  def __init__(self, window_coder):
    """Create a new WindowFn with compatible coder.
    To be applied to PCollections with windows that are compatible with the
    given coder.

    Arguments:
      window_coder: coders.Coder object to be used on windows.
    """
    super().__init__()
    if window_coder is None:
      raise ValueError('window_coder should not be None')
    self._window_coder = window_coder

  def assign(self, assign_context):
    if assign_context.window is None:
      raise ValueError(
          'assign_context.window should not be None. '
          'This might be due to a DoFn returning a TimestampedValue.')
    return [assign_context.window]

  def get_window_coder(self):
    return self._window_coder


def reify_metadata_default_window(
    element, timestamp=DoFn.TimestampParam, pane_info=DoFn.PaneInfoParam):
  key, value = element
  if timestamp == window.MIN_TIMESTAMP:
    timestamp = None

View on GitHub (pinned to 12126d8942)

Solutions

  1. Pass a real window coder, usually windowing.get_window_coder(pcoll.windowing) or window_fn.get_window_coder()
  2. Ensure the pipeline's windowing strategy is set before the transform expands
  3. In tests, construct the coder explicitly (e.g. coders.IntervalWindowCoder) instead of None

Example fix

// before
helper = _ReassignWindowsDoFn._WindowCoderPlaceholder(window_coder=None)
// after
coder = pcoll.windowing.windowfn.get_window_coder()
helper = _ReassignWindowsDoFn._WindowCoderPlaceholder(window_coder=coder)
Defensive patterns

Strategy: validation

Validate before calling

if window_coder is None:
    raise ValueError('window_coder required')

Prevention

When it happens

Trigger: Internally instantiating the reassign-windows helper (or subclassing it) with window_coder=None — typically when a custom Windowing/WindowFn plumbing path forgets to fetch get_window_coder().

Common situations: Custom transform code that wires a WindowFn but skips its window coder; refactors that drop the coder argument; unit-testing the DoFn directly with None.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/a70ed0c88e25e578. Report an issue: GitHub.