{"record":{"id":"e0a16aeab934fb2e","repo":"apache/beam","slug":"default-values-are-not-yet-supported-in-combineglobally-if","errorCode":null,"errorMessage":"Default values are not yet supported in CombineGlobally() if the output  PCollection is not windowed by GlobalWindows. Instead, use CombineGlobally().without_defaults() to output an empty PCollection if the input PCollection is empty, or CombineGlobally().as_singleton_view() to get the default output of the CombineFn if the input PCollection is empty.","messagePattern":"Default values are not yet supported in CombineGlobally\\(\\) if the output  PCollection is not windowed by GlobalWindows\\. Instead, use CombineGlobally\\(\\)\\.without_defaults\\(\\) to output an empty PCollection if the input PCollection is empty, or CombineGlobally\\(\\)\\.as_singleton_view\\(\\) to get the default output of the CombineFn if the input PCollection is empty\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/core.py","lineNumber":3019,"sourceCode":"    if not self.has_defaults and not self.as_view:\n      return combined\n\n    elif self.as_view:\n      if self.has_defaults:\n        try:\n          combine_fn.setup(*self.args, **self.kwargs)\n          # This is called in the main program, but cannot be avoided\n          # in the as_view case as it must be available to all windows.\n          default_value = combine_fn.apply([], *self.args, **self.kwargs)\n        finally:\n          combine_fn.teardown(*self.args, **self.kwargs)\n      else:\n        default_value = pvalue.AsSingleton._NO_DEFAULT\n      return pvalue.AsSingleton(combined, default_value=default_value)\n\n    else:\n      if pcoll.windowing.windowfn != GlobalWindows():\n        raise ValueError(\n            \"Default values are not yet supported in CombineGlobally() if the \"\n            \"output  PCollection is not windowed by GlobalWindows. \"\n            \"Instead, use CombineGlobally().without_defaults() to output \"\n            \"an empty PCollection if the input PCollection is empty, \"\n            \"or CombineGlobally().as_singleton_view() to get the default \"\n            \"output of the CombineFn if the input PCollection is empty.\")\n\n      # log the error for this ill-defined streaming case now\n      if not pcoll.is_bounded and not pcoll.windowing.is_default():\n        _LOGGER.error(\n            \"When combining elements in unbounded collections with \"\n            \"the non-default windowing strategy, you must explicitly \"\n            \"specify how to define the combined result of an empty window. \"\n            \"Please use CombineGlobally().without_defaults() to output \"\n            \"an empty PCollection if the input PCollection is empty.\")\n\n      def typed(transform):\n        # TODO(robertwb): We should infer this.","sourceCodeStart":3001,"sourceCodeEnd":3037,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/core.py#L3001-L3037","documentation":"When a CombineGlobally has default values enabled (i.e. neither without_defaults nor as_singleton_view was used) but the input PCollection is not windowed by GlobalWindows, Beam cannot safely provide a default output per window, so it raises this ValueError at pipeline construction time.","triggerScenarios":"Applying beam.CombineGlobally(fn) (with defaults) to a PCollection whose windowing is e.g. FixedWindows/SlidingWindows — i.e. any non-global windowfn — with default_value semantics requested.","commonSituations":"Stream/windowed pipelines where a developer adds a combine for aggregates and expects an empty-result default; Beam requires explicitly choosing the empty-PCollection or singleton-view behavior instead.","solutions":["Call .without_defaults() to get an empty output PCollection when input is empty","Call .as_singleton_view() to obtain the CombineFn's default as a singleton view","Switch the PCollection to GlobalWindows only if that is genuinely correct for the aggregation"],"exampleFix":"// before\npcoll | beam.CombineGlobally(sum)\n// after\npcoll | beam.CombineGlobally(sum).without_defaults()","handlingStrategy":"validation","validationCode":"from apache_beam import window\nif pcoll.windowing.windowfn != window.GlobalWindows() and combine_defaults_requested:\n    combine = combine.without_defaults()  # or .as_singleton_view()","typeGuard":"def defaults_safe_for_windowing(pcoll) -> bool:\n    return pcoll.windowing.windowfn == pcoll.windowing.windowfn.__class__() and type(pcoll.windowing.windowfn).__name__ == 'GlobalWindows'","tryCatchPattern":"try:\n    expanded = pcoll | beam.CombineGlobally(fn)\nexcept ValueError as e:\n    if 'Default values are not yet supported' in str(e):\n        expanded = pcoll | beam.CombineGlobally(fn).without_defaults()\n    else:\n        raise","preventionTips":["Always call .without_defaults() or .as_singleton_view() when combining windowed streams","Check pcoll.windowing.windowfn before adding combine transforms","Prefer without_defaults in streaming pipelines to keep empty-window semantics explicit"],"tags":["python","apache-beam","combine","windowing"],"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"}