{"record":{"id":"4b4f391ff269cdff","repo":"apache/beam","slug":"start-bundle-should-not-output-any-elements-but-got-s","errorCode":null,"errorMessage":"Start Bundle should not output any elements but got %s","messagePattern":"Start Bundle should not output any elements but got (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/runners/common.py","lineNumber":1856,"sourceCode":"      for timestamp in windowed_batch.timestamps:\n        watermark_estimator.observe_timestamp(timestamp)\n\n    if tag is None:\n      self.main_receivers.receive_batch(windowed_batch)\n    else:\n      self.tagged_receivers[tag].receive_batch(windowed_batch)\n\n  def _verify_batch_output(self, result):\n    if isinstance(result, (WindowedValue, TimestampedValue)):\n      raise TypeError(\n          f\"Received {type(result).__name__} from DoFn that was \"\n          \"expected to produce a batch.\")\n\n  def start_bundle_outputs(self, results):\n    \"\"\"Validate that start_bundle does not output any elements\"\"\"\n    if results is None:\n      return\n    raise RuntimeError(\n        'Start Bundle should not output any elements but got %s' % results)\n\n  def finish_bundle_outputs(self, results):\n    \"\"\"Dispatch the result of finish_bundle to the appropriate receivers.\n\n    A value wrapped in a TaggedOutput object will be unwrapped and\n    then dispatched to the appropriate indexed output.\n    \"\"\"\n    if results is None:\n      return\n\n    for result in results:\n      tag = None\n      if isinstance(result, TaggedOutput):\n        tag = result.tag\n        if not isinstance(tag, str):\n          raise TypeError('In %s, tag %s is not a string' % (self, tag))\n        result = result.value","sourceCodeStart":1838,"sourceCodeEnd":1874,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/runners/common.py#L1838-L1874","documentation":"Beam DoFn lifecycle requires that start_bundle produces no output; only process() and finish_bundle() may emit elements. start_bundle_outputs raises RuntimeError if the start_bundle method returned anything other than None.","triggerScenarios":"Implementing `def start_bundle(self)` in a DoFn with a `return some_value` (yield also counts, since a generator result is passed in) instead of returning None or having no return statement.","commonSituations":"Misunderstanding the lifecycle API and trying to emit warm-up/initializer elements in start_bundle; copying a finish_bundle pattern into start_bundle.","solutions":["Remove the return/yield statements from start_bundle; perform only per-bundle setup (e.g. initializing clients).","Move element emission to process() (per element) or finish_bundle() (per bundle, must yield WindowedValue).","If side-effect setup is needed per window instead, restructure the pipeline with windowing-aware transforms."],"exampleFix":"// before\ndef start_bundle(self):\n    yield 'warmup'  # RuntimeError\n// after\ndef start_bundle(self):\n    self.client = create_client()  # setup only, no output","handlingStrategy":"validation","validationCode":"assert start_bundle() is None, 'start_bundle must not produce output'","typeGuard":"def is_valid_start_bundle_result(r):\n    return r is None","tryCatchPattern":"try:\n    invoker.invoke_start_bundle()\nexcept RuntimeError as e:\n    if 'Start Bundle should not output' in str(e):\n        raise ValueError('DoFn.start_bundle must not yield/return elements') from e\n    raise","preventionTips":["Keep start_bundle limited to side-effect-free or client-setup code with no return/yield.","Code-review rule: any `yield` inside start_bundle is a bug.","Run DoFn unit tests via the DirectRunner, which exercises start_bundle."],"tags":["python","apache-beam","dofn-lifecycle","runtime-error"],"backgroundTag":"unsupported-operation","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"}