{"record":{"id":"e5e008110581408b","repo":"apache/beam","slug":"timestamp-not-accessible-in-this-context","errorCode":null,"errorMessage":"timestamp not accessible in this context","messagePattern":"timestamp not accessible in this context","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/runners/common.py","lineNumber":1946,"sourceCode":"    self.state = state\n    if element is not None:\n      self.set_element(element)\n\n  def set_element(self, windowed_value):\n    # type: (Optional[WindowedValue]) -> None\n    self.windowed_value = windowed_value\n\n  @property\n  def element(self):\n    if self.windowed_value is None:\n      raise AttributeError('element not accessible in this context')\n    else:\n      return self.windowed_value.value\n\n  @property\n  def timestamp(self):\n    if self.windowed_value is None:\n      raise AttributeError('timestamp not accessible in this context')\n    else:\n      return self.windowed_value.timestamp\n\n  @property\n  def windows(self):\n    if self.windowed_value is None:\n      raise AttributeError('windows not accessible in this context')\n    else:\n      return self.windowed_value.windows\n","sourceCodeStart":1928,"sourceCodeEnd":1956,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/runners/common.py#L1928-L1956","documentation":"Same family as the element error: DoFnContext.timestamp raises AttributeError('timestamp not accessible in this context') when windowed_value is None, i.e. the current context has no element and hence no per-element timestamp.","triggerScenarios":"Accessing ctx.timestamp (or self.timestamp via context) in start_bundle/finish_bundle or any context constructed without a WindowedValue.","commonSituations":"Reading the current element timestamp during bundle lifecycle methods; relying on stale context state across process calls; hand-rolled DoFn invocation in tests without a windowed value.","solutions":["Read timestamps inside process() only, e.g. via `timestamp=beam.DoFn.TimestampParam` or ctx.timestamp there.","Capture the timestamp in process() and store it on the DoFn instance if finish_bundle needs it.","In tests, construct the context with WindowedValue(value, timestamp, windows)."],"exampleFix":"// before\ndef finish_bundle(self):\n    ts = self.timestamp  # AttributeError\n// after\ndef process(self, element, ts=beam.DoFn.TimestampParam):\n    self.last_ts = ts\n\ndef finish_bundle(self):\n    ts = self.last_ts","handlingStrategy":"try-catch","validationCode":"if getattr(ctx, 'windowed_value', None) is None:\n    ts = None\nelse:\n    ts = ctx.timestamp","typeGuard":"def has_timestamp(ctx):\n    return getattr(ctx, 'windowed_value', None) is not None","tryCatchPattern":"try:\n    ts = ctx.timestamp\nexcept AttributeError as e:\n    if 'timestamp not accessible' in str(e):\n        ts = MIN_TIMESTAMP\n    else:\n        raise","preventionTips":["Use beam.DoFn.TimestampParam in process() rather than ctx.timestamp.","Store per-element timestamps in instance state during process() if finish_bundle needs them.","Never access element-timestamp context outside of process()."],"tags":["python","apache-beam","dofn-context","timestamp","attribute-error"],"backgroundTag":"attribute-not-accessible","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"}