{"record":{"id":"17ad7b4da95260d3","repo":"apache/beam","slug":"must-provide-context-when-not-using-simpleinvoker","errorCode":null,"errorMessage":"Must provide context when not using SimpleInvoker","messagePattern":"Must provide context when not using SimpleInvoker","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/runners/common.py","lineNumber":537,"sourceCode":"                      before invoking the process method.\n        process_invocation: If True, this function may return an invoker that\n                            performs extra optimizations for invoking process()\n                            method efficiently.\n        user_state_context: The UserStateContext instance for the current\n                            Stateful DoFn.\n        bundle_finalizer_param: The param that passed to a process method, which\n                                allows a callback to be registered.\n    \"\"\"\n    side_inputs = side_inputs or []\n    use_per_window_invoker = process_invocation and (\n        side_inputs or input_args or input_kwargs or\n        signature.process_method.defaults or\n        signature.process_batch_method.defaults or signature.is_stateful_dofn())\n    if not use_per_window_invoker:\n      return SimpleInvoker(output_handler, signature)\n    else:\n      if context is None:\n        raise TypeError(\"Must provide context when not using SimpleInvoker\")\n      return PerWindowInvoker(\n          output_handler,\n          signature,\n          context,\n          side_inputs,\n          input_args,\n          input_kwargs,\n          user_state_context,\n          bundle_finalizer_param)\n\n  def invoke_process(\n      self,\n      windowed_value,  # type: WindowedValue\n      restriction=None,\n      watermark_estimator_state=None,\n      additional_args=None,\n      additional_kwargs=None):\n    # type: (...) -> Iterable[SplitResultResidual]","sourceCodeStart":519,"sourceCodeEnd":555,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/runners/common.py#L519-L555","documentation":"DoFnInvoker.create_invoker selects SimpleInvoker when no per-window invocation features (side inputs, special params, stateful DoFn) are needed; otherwise it builds PerWindowInvoker, which requires a context object. A TypeError is raised if context is None in that case.","triggerScenarios":"create_invoker(output_handler, signature, ...) with a signature needing PerWindowInvoker (defaults present or stateful DoFn) but context=None, e.g. custom runner or test harness invoking a side-input-consuming DoFn.","commonSituations":"Hand-rolled runners/tests calling create_invoker without a DoFnContext; frameworks wiring DoFn invocation that regress on context plumbing.","solutions":["Pass a DoFnContext instance (e.g. a simple DoFnContext / RunnerContext) as the context argument","If the DoFn truly needs no special params, use SimpleInvoker by ensuring signature has no defaults/state","Update custom runner code to construct a context as apache_beam.runners.common expects"],"exampleFix":"// before\nDoFnInvoker.create_invoker(sig, output_handler)  # sig uses side inputs\n// after\nDoFnInvoker.create_invoker(sig, output_handler, context=DoFnContext(self))","handlingStrategy":"type-guard","validationCode":"assert context is not None, 'PerWindowInvoker requires a DoFnContext'","typeGuard":null,"tryCatchPattern":"try:\n    invoker = DoFnInvoker.create_invoker(sig, handler, context=None)\nexcept TypeError as e:\n    invoker = DoFnInvoker.create_invoker(sig, handler, context=DoFnContext(None))","preventionTips":["Always supply a context when invoking DoFns with special params or side inputs","Prefer SimpleInvoker paths only for trivial DoFns"],"tags":["python","apache-beam","invoker"],"backgroundTag":"null-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}