{"record":{"id":"23f3d7704bc9ffe8","repo":"apache/beam","slug":"mixing-values-in-different-pipelines-is-not-allowed-r-r","errorCode":null,"errorMessage":"Mixing values in different pipelines is not allowed.\n{%r} != {%r}","messagePattern":"Mixing values in different pipelines is not allowed\\.\n(.+?) != (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/ptransform.py","lineNumber":625,"sourceCode":"      # pylint: disable=wrong-import-order, wrong-import-position\n      from apache_beam import pipeline\n      from apache_beam.options.pipeline_options import PipelineOptions\n\n      # pylint: enable=wrong-import-order, wrong-import-position\n      p = pipeline.Pipeline('DirectRunner', PipelineOptions(sys.argv))\n    else:\n      if not pipelines:\n        if self.pipeline is not None:\n          p = self.pipeline\n        else:\n          raise ValueError(\n              '\"%s\" requires a pipeline to be specified '\n              'as there are no deferred inputs.' % self.label)\n      else:\n        p = self.pipeline or pipelines[0]\n        for pp in pipelines:\n          if p != pp:\n            raise ValueError(\n                'Mixing values in different pipelines is not allowed.'\n                '\\n{%r} != {%r}' % (p, pp))\n      deferred = not getattr(p.runner, 'is_eager', False)\n    # pylint: disable=wrong-import-order, wrong-import-position\n    from apache_beam.transforms.core import Create\n\n    # pylint: enable=wrong-import-order, wrong-import-position\n    replacements = {\n        id(v): p | 'CreatePInput%s' % ix >> Create(v, reshuffle=False)\n        for (ix, v) in enumerate(pvalues)\n        if not isinstance(v, pvalue.PValue) and v is not None\n    }\n    pvalueish = _SetInputPValues().visit(pvalueish, replacements)\n    self.pipeline = p\n    result = p.apply(self, pvalueish, label)\n    if deferred:\n      return result\n    _allocate_materialized_pipeline(p)","sourceCodeStart":607,"sourceCodeEnd":643,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/ptransform.py#L607-L643","documentation":"When a PTransform is applied to multiple inputs, all input PCollections must belong to the same Pipeline object. __ror__ compares collected pipelines and raises ValueError if any differ, because mixing PCollections across pipelines is undefined in Beam.","triggerScenarios":"Combining PCollections from two different `beam.Pipeline()` instances (e.g. p1 | Join(p2_read_value)) or reusing a PCollection created under an old pipeline in a new one.","commonSituations":"Building two pipelines in a script/REPL and later trying to union/join them; iterating pipelines in tests and mixing fixtures from different pipelines.","solutions":["Create all inputs within the same Pipeline instance.","Re-read the source data under the target pipeline instead of reusing a PCollection from another pipeline.","Restructure code so a single pipeline owns every PCollection being combined."],"exampleFix":"// before\np1 = beam.Pipeline(); p2 = beam.Pipeline()\na = p1 | 'A' >> beam.Create([1])\nb = p2 | 'B' >> beam.Create([2])\ncombined = a | beam.Flatten(passthrough=b)  # mixes pipelines\n// after\np = beam.Pipeline()\na = p | 'A' >> beam.Create([1])\nb = p | 'B' >> beam.Create([2])\ncombined = (a, b) | beam.Flatten()","handlingStrategy":"validation","validationCode":"pipelines = {getattr(v, 'pipeline', None) for v in inputs if hasattr(v, 'pipeline')}\nassert len(pipelines) <= 1, f\"inputs span multiple pipelines: {pipelines}\"","typeGuard":null,"tryCatchPattern":"try:\n  combined = a | flatten_b ...\nexcept ValueError as e:\n  if 'Mixing values in different pipelines' in str(e):\n    # rebuild all inputs under one pipeline\n    raise\n  raise","preventionTips":["Create every PCollection under the same Pipeline object","Avoid caching PCollections across pipeline lifetimes in tests/scripts"],"tags":["python","apache-beam","pipeline"],"backgroundTag":"invalid-argument-value","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"}