{"record":{"id":"c2c12d52c8a47fb1","repo":"apache/beam","slug":"no-timestamp-in-this-context","errorCode":null,"errorMessage":"No timestamp in this context.","messagePattern":"No timestamp in this context\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/runners/common.py","lineNumber":1899,"sourceCode":"\n      if tag is None:\n        self.main_receivers.receive(windowed_value)\n      else:\n        self.tagged_receivers[tag].receive(windowed_value)\n\n\nclass _NoContext(WindowFn.AssignContext):\n  \"\"\"An uninspectable WindowFn.AssignContext.\"\"\"\n  NO_VALUE = object()\n\n  def __init__(self, value, timestamp=NO_VALUE):\n    self.value = value\n    self._timestamp = timestamp\n\n  @property\n  def timestamp(self):\n    if self._timestamp is self.NO_VALUE:\n      raise ValueError('No timestamp in this context.')\n    else:\n      return self._timestamp\n\n  @property\n  def existing_windows(self):\n    raise ValueError('No existing_windows in this context.')\n\n\nclass DoFnState(object):\n  \"\"\"For internal use only; no backwards-compatibility guarantees.\n\n  Keeps track of state that DoFns want, currently, user counters.\n  \"\"\"\n  def __init__(self, counter_factory):\n    self.step_name = ''\n    self._counter_factory = counter_factory\n\n  def counter_for(self, aggregator):","sourceCodeStart":1881,"sourceCodeEnd":1917,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/runners/common.py#L1881-L1917","documentation":"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.","triggerScenarios":"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.","commonSituations":"Unit-testing DoFns with DoFnTester without supplying timestamps; calling process logic manually with a hand-built ProcessContext.","solutions":["Provide a timestamp when constructing the test context, e.g. `t = DoFnTester(...)` then `t.process_with_context(..., timestamp=...)` or pass a WindowedValue.","Guard access: check whether the context actually has a timestamp before reading it.","Upgrade DoFnTester usage to newer beam.testing.test_pipeline / direct runner approaches that populate the context fully."],"exampleFix":"// before\ntester = DoFnTester(MyDoFn())\nprint(tester.run_and_get_results(['a'])[0].timestamp)\n// after\nfrom apache_beam import WindowedValue\nimport apache_beam.transforms.window as window\ntester = DoFnTester(MyDoFn())\ntester.process(WindowedValue('a', 0, (window.GlobalWindow(),)))  # timestamp present","handlingStrategy":"try-catch","validationCode":"if ctx._timestamp is DoFnContext.NO_VALUE:\n    raise SkipElement('context has no timestamp')","typeGuard":"def has_timestamp(ctx):\n    return getattr(ctx, '_timestamp', DoFnContext.NO_VALUE) is not DoFnContext.NO_VALUE","tryCatchPattern":"try:\n    ts = ctx.timestamp\nexcept ValueError as e:\n    if 'No timestamp in this context' in str(e):\n        ts = None  # fall back to default timestamp\n    else:\n        raise","preventionTips":["In tests, feed inputs as WindowedValue so timestamps are populated.","Only read ctx.timestamp inside process(), never in start_bundle/finish_bundle.","Prefer the TimestampParam DoFn parameter over raw context access."],"tags":["python","apache-beam","process-context","timestamp","value-error"],"backgroundTag":"missing-required-argument","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"}