{"record":{"id":"404ee8437c575eb5","repo":"apache/beam","slug":"allow-unsafe-userstate-in-process-is-incompatible-with","errorCode":null,"errorMessage":"allow_unsafe_userstate_in_process is incompatible with exception handling done with subprocesses or timeouts. If you need this feature, comment in https://github.com/apache/beam/issues/35976","messagePattern":"allow_unsafe_userstate_in_process is incompatible with exception handling done with subprocesses or timeouts\\. If you need this feature, comment in https://github\\.com/apache/beam/issues/35976","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/core.py","lineNumber":2384,"sourceCode":"    self._error_handler = error_handler\n    self._on_failure_callback = on_failure_callback\n    self._allow_unsafe_userstate_in_process = allow_unsafe_userstate_in_process\n    self._resource_hints = resource_hints\n    self._pardo_type_hints = pardo_type_hints\n    self._extra_tags = None\n\n  def with_outputs(self, *tags, main=None):\n    self._extra_tags = tags\n    if main is not None:\n      self._main_tag = main\n    return self\n\n  def _build_pardo(self, pcoll):\n    \"\"\"Build the inner ParDo with the exception-handling wrapper DoFn.\"\"\"\n    if self._allow_unsafe_userstate_in_process:\n      if self._use_subprocess or self._timeout:\n        # TODO(https://github.com/apache/beam/issues/35976): Implement this\n        raise Exception(\n            'allow_unsafe_userstate_in_process is incompatible with ' +\n            'exception handling done with subprocesses or timeouts. If you ' +\n            'need this feature, comment in ' +\n            'https://github.com/apache/beam/issues/35976')\n    if self._use_subprocess:\n      wrapped_fn = _SubprocessDoFn(self._fn, timeout=self._timeout)\n    elif self._timeout:\n      wrapped_fn = _TimeoutDoFn(self._fn, timeout=self._timeout)\n    else:\n      wrapped_fn = self._fn\n    pardo = ParDo(\n        _ExceptionHandlingWrapperDoFn(\n            wrapped_fn,\n            self._dead_letter_tag,\n            self._exc_class,\n            self._partial,\n            self._on_failure_callback,\n            self._allow_unsafe_userstate_in_process,","sourceCodeStart":2366,"sourceCodeEnd":2402,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/core.py#L2366-L2402","documentation":"apache_beam raises this Exception when _allow_unsafe_userstate_in_process is enabled on a DoFn whose exception handling uses subprocesses or timeouts. Such exception handling re-executes or isolates user code in a way that conflicts with reusing in-process user state, so the combination is explicitly unimplemented (tracked as Beam issue #35976).","triggerScenarios":"Constructing a ParDo with allow_unsafe_userstate_in_process=True together with use_subprocess=True or a non-None timeout, then building the transform via _build_pardo (e.g. at pipeline expansion time).","commonSituations":"Developers enabling the unsafe-user-state opt-in for performance, while also using the exception-handling wrapper with timeouts or subprocess isolation, hit this at pipeline graph construction rather than runtime data processing.","solutions":["Turn off allow_unsafe_userstate_in_process, or","Remove use_subprocess and timeout so exception handling stays in-process","Comment/upvote the feature request at https://github.com/apache/beam/issues/35976 if you need the combination"],"exampleFix":"// before\nParDo(fn, timeout=30, allow_unsafe_userstate_in_process=True)\n// after\nParDo(fn, timeout=30)  # drop allow_unsafe_userstate_in_process","handlingStrategy":"validation","validationCode":"if allow_unsafe_userstate_in_process and (use_subprocess or timeout is not None):\n    raise ValueError('allow_unsafe_userstate_in_process cannot be combined with subprocess/timeout exception handling (beam#35976)')","typeGuard":"def compatible_exc_handling(unsafe_userstate: bool, use_subprocess: bool, timeout) -> bool:\n    return not (unsafe_userstate and (use_subprocess or timeout is not None))","tryCatchPattern":"try:\n    expand(pardo)\nexcept Exception as e:\n    if 'allow_unsafe_userstate_in_process is incompatible' in str(e):\n        retry_without_unsafe_userstate()  # rebuild transform with the flag off\n    else:\n        raise","preventionTips":["Track beam issue 35976 before opting into unsafe user state","Keep exception-handling options in a single config object validated at pipeline-build time"],"tags":["python","apache-beam","pardo","unimplemented-feature"],"backgroundTag":"conflicting-config-options","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"}