apache/beam · error · ValueError

No timestamp in this context.

Error message

No timestamp in this context.

What it means

DoFn ProcessContext.timestamp raises ValueError('No timestamp in this context.') when no timestamp was provided to the context (the internal _timestamp sentinel NO_VALUE is set). Beam only populates the timestamp in certain invocation contexts (e.g. inside process with an element); user-created contexts (like in DoFnTester or direct instantiation) without a timestamp cannot provide one.

Source

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

      if tag is None:
        self.main_receivers.receive(windowed_value)
      else:
        self.tagged_receivers[tag].receive(windowed_value)


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):

View on GitHub (pinned to 12126d8942)

Solutions

  1. Provide a timestamp when constructing the test context, e.g. `t = DoFnTester(...)` then `t.process_with_context(..., timestamp=...)` or pass a WindowedValue.
  2. Guard access: check whether the context actually has a timestamp before reading it.
  3. Upgrade DoFnTester usage to newer beam.testing.test_pipeline / direct runner approaches that populate the context fully.

Example fix

// before
tester = DoFnTester(MyDoFn())
print(tester.run_and_get_results(['a'])[0].timestamp)
// after
from apache_beam import WindowedValue
import apache_beam.transforms.window as window
tester = DoFnTester(MyDoFn())
tester.process(WindowedValue('a', 0, (window.GlobalWindow(),)))  # timestamp present
Defensive patterns

Strategy: try-catch

Validate before calling

if ctx._timestamp is DoFnContext.NO_VALUE:
    raise SkipElement('context has no timestamp')

Type guard

def has_timestamp(ctx):
    return getattr(ctx, '_timestamp', DoFnContext.NO_VALUE) is not DoFnContext.NO_VALUE

Try / catch

try:
    ts = ctx.timestamp
except ValueError as e:
    if 'No timestamp in this context' in str(e):
        ts = None  # fall back to default timestamp
    else:
        raise

Prevention

When it happens

Trigger: Accessing `ctx.timestamp` in a DoFn where the context was created without a timestamp — typically in tests using DoFnTester with a value only, or code paths invoking the DoFn outside normal runner element processing.

Common situations: Unit-testing DoFns with DoFnTester without supplying timestamps; calling process logic manually with a hand-built ProcessContext.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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