apache/beam · error · ValueError

No existing_windows in this context.

Error message

No existing_windows in this context.

What it means

The sibling of the timestamp check: ProcessContext.existing_windows unconditionally raises ValueError('No existing_windows in this context.') because this context type never carries window information. Any code path that asks for windows through this context is invalid by construction.

Solutions

  1. Access windows through the correct mechanism: declare the DoFn with the windows-related context (e.g. use the `window` DoFn parameter via beam.DoFn.ProcessContext or @beam.DoFn.window_param-style access / process(ctx) with windowed value).
  2. In tests, wrap inputs in WindowedValue so window info is available through the runner path.
  3. Refactor to not need input windows; use beam.WindowInto or window-aware transforms instead.

Example fix

// before
class MyDoFn(beam.DoFn):
    def process(self, ctx):
        print(ctx.existing_windows)  # always raises
// after
class MyDoFn(beam.DoFn):
    def process(self, element, window=beam.DoFn.WindowParam):
        print(window)  # proper window access
Defensive patterns

Strategy: type-guard

Validate before calling

if not isinstance(ctx, type(None)) and getattr(ctx, 'existing_windows', None) is None:
    skip_window_logic()

Type guard

def has_windows(ctx):
    try:
        _ = ctx.existing_windows
        return True
    except ValueError:
        return False

Try / catch

try:
    windows = ctx.existing_windows
except ValueError:
    windows = [GlobalWindow()]  # conservative default
    log.warning('Window info unavailable; assuming global window')

Prevention

When it happens

Trigger: Accessing `ctx.existing_windows` on a ProcessContext (e.g. inside a DoFn's process via the process context or in tests) when the runner-provided context does not expose windows.

Common situations: Trying to read input windows in a DoFn without the proper context (e.g. via DoFnTester or a plain Context rather than the windowed receiver); assuming windows are always available in ctx.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at sdks/python/apache_beam/runners/common.py:1905

class _NoContext(WindowFn.AssignContext):
  """An uninspectable WindowFn.AssignContext."""
  NO_VALUE = object()

  def __init__(self, value, timestamp=NO_VALUE):
    self.value = value
    self._timestamp = timestamp

  @property
  def timestamp(self):
    if self._timestamp is self.NO_VALUE:
      raise ValueError('No timestamp in this context.')
    else:
      return self._timestamp

  @property
  def existing_windows(self):
    raise ValueError('No existing_windows in this context.')


class DoFnState(object):
  """For internal use only; no backwards-compatibility guarantees.

  Keeps track of state that DoFns want, currently, user counters.
  """
  def __init__(self, counter_factory):
    self.step_name = ''
    self._counter_factory = counter_factory

  def counter_for(self, aggregator):
    """Looks up the counter for this aggregator, creating one if necessary."""
    return self._counter_factory.get_aggregator_counter(
        self.step_name, aggregator)


# TODO(robertwb): Replace core.DoFnContext with this.

View on GitHub (pinned to 12126d8942)