{"record":{"id":"fc725cd9beef25f0","repo":"apache/beam","slug":"sessions-is-not-allowed-in-side-inputs-sideinputs","errorCode":null,"errorMessage":"Sessions is not allowed in side inputs","messagePattern":"Sessions is not allowed in side inputs","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/sideinputs.py","lineNumber":58,"sourceCode":"\nSIDE_INPUT_PREFIX = 'python_side_input'\n\nSIDE_INPUT_REGEX = SIDE_INPUT_PREFIX + '([0-9]+)(-.*)?$'\n\n\n# Top-level function so we can identify it later.\ndef _global_window_mapping_fn(\n    w, global_window=window.GlobalWindow()) -> window.GlobalWindow:\n  return global_window\n\n\ndef default_window_mapping_fn(\n    target_window_fn: window.WindowFn) -> WindowMappingFn:\n  if target_window_fn == window.GlobalWindows():\n    return _global_window_mapping_fn\n\n  if isinstance(target_window_fn, window.Sessions):\n    raise RuntimeError(\"Sessions is not allowed in side inputs\")\n\n  def map_via_end(source_window: window.BoundedWindow) -> window.BoundedWindow:\n    return list(\n        target_window_fn.assign(\n            window.WindowFn.AssignContext(\n                source_window.max_timestamp(), window=source_window)))[-1]\n\n  return map_via_end\n\n\ndef get_sideinput_index(tag: str) -> int:\n  match = re.match(SIDE_INPUT_REGEX, tag, re.DOTALL)\n  if match:\n    return int(match.group(1))\n  else:\n    raise RuntimeError(\"Invalid tag %r\" % tag)\n\n","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/sideinputs.py#L40-L76","documentation":"default_window_mapping_fn builds a WindowMappingFn that maps source windows to side-input windows. Session windowing is explicitly rejected because mapping an arbitrary source window into session windows is ill-defined (sessions depend on the data itself). The library raises RuntimeError instead of guessing a mapping.","triggerScenarios":"Using pvalue.AsIter(side_input) (or AsList/AsSingleton) on a PCollection windowed with window.Sessions() while the main collection uses a different windowing; default_window_mapping_fn is called with a Sessions instance and raises.","commonSituations":"Joining or enriching a sessionized stream with side inputs; users converting a DoFn to take side inputs after re-windowing data into sessions.","solutions":["Re-window the side-input PCollection to a supported windowing (GlobalWindows, FixedWindows, etc.) before passing it as a side input.","Use a plain join/CoGroupByKey instead of a side input when both sides are session-windowed.","Provide an explicit window_mapping_fn on the view (e.g. via a custom SideInputMap / default_window_selection_fn) rather than relying on the default mapping."],"exampleFix":"// before\nside = pcoll | 'sessions' >> beam.WindowInto(window.Sessions(600))\nresult = main | beam.Map(lambda x, s: ..., side=beam.pvalue.AsIter(side))\n// after\nside_fixed = side | beam.WindowInto(window.GlobalWindows())\nresult = main | beam.Map(lambda x, s: ..., side=beam.pvalue.AsIter(side_fixed))","handlingStrategy":"validation","validationCode":"from apache_beam import window\nif isinstance(side_pcoll.windowing.windowfn, window.Sessions):\n    raise ValueError('Side input PCollection must not use Sessions windowing')","typeGuard":"def is_side_input_safe(pcoll) -> bool:\n    from apache_beam import window\n    fn = pcoll.windowing.windowfn\n    return not isinstance(fn, window.Sessions)","tryCatchPattern":"try:\n    result = main | beam.Map(fn, side=beam.pvalue.AsIter(side))\nexcept RuntimeError as e:\n    if 'Sessions is not allowed in side inputs' in str(e):\n        side = side | beam.WindowInto(window.GlobalWindows())\n        result = main | beam.Map(fn, side=beam.pvalue.AsIter(side))","preventionTips":["Never attach side inputs to session-windowed PCollections.","Re-window to GlobalWindows before creating views (AsIter/AsList/AsSingleton).","Document windowing requirements of DoFns that consume side inputs."],"tags":["python","apache-beam","windowing","side-inputs"],"backgroundTag":"unsupported-operation","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"}