{"record":{"id":"a1761483053fc89c","repo":"apache/beam","slug":"pcollection-not-part-of-a-pipeline","errorCode":null,"errorMessage":"PCollection not part of a pipeline.","messagePattern":"PCollection not part of a pipeline\\.","errorType":"exception","errorClass":"TransformError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/ptransform.py","lineNumber":571,"sourceCode":"\n  def __repr__(self):\n    return '<%s at %s>' % (self._str_internal(), hex(id(self)))\n\n  def _str_internal(self):\n    return '%s(PTransform)%s%s%s' % (\n        self.__class__.__name__,\n        ' label=[%s]' % self.label if\n        (hasattr(self, 'label') and self.label) else '',\n        ' inputs=%s' % str(self.inputs) if\n        (hasattr(self, 'inputs') and self.inputs) else '',\n        ' side_inputs=%s' % str(self.side_inputs) if self.side_inputs else '')\n\n  def _check_pcollection(self, pcoll):\n    # type: (pvalue.PCollection) -> None\n    if not isinstance(pcoll, pvalue.PCollection):\n      raise error.TransformError('Expecting a PCollection argument.')\n    if not pcoll.pipeline:\n      raise error.TransformError('PCollection not part of a pipeline.')\n\n  def get_windowing(self, inputs):\n    # type: (Any) -> Windowing\n\n    \"\"\"Returns the window function to be associated with transform's output.\n\n    By default most transforms just return the windowing function associated\n    with the input PCollection (or the first input if several).\n    \"\"\"\n    if inputs:\n      return inputs[0].windowing\n    else:\n      from apache_beam.transforms.core import Windowing\n      from apache_beam.transforms.window import GlobalWindows\n\n      # TODO(robertwb): Return something compatible with every windowing?\n      return Windowing(GlobalWindows())\n","sourceCodeStart":553,"sourceCodeEnd":589,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/ptransform.py#L553-L589","documentation":"_check_pcollection also verifies the PCollection belongs to a pipeline. A PCollection-like object whose .pipeline is None/falsy triggers TransformError, because transforms must run within a pipeline context to schedule steps.","triggerScenarios":"Constructing or deserializing a PCollection manually without attaching it to an applied pipeline; using a PCollection from a different/pipeline-scoped context after the pipeline was discarded; pickling/dill issues that dropped the pipeline reference.","commonSituations":"Creating PCollection objects directly in unit tests without p | transform; cross-pipeline reuse of outputs; corrupted notebook state where the pipeline object was rebuilt but old PCollections retained.","solutions":["Produce PCollections via pipeline | transform instead of instantiating them directly","Use the output of the same active pipeline the transform will run in","Recreate the PCollection under the current pipeline if the old pipeline was discarded","In tests, build with TestPipeline and real transform application"],"exampleFix":"// before\npcoll = pvalue.PCollection(None)  # no pipeline attached\nmy_transform.expand(pcoll)\n// after\npcoll = pipeline | beam.Create([...])\nmy_transform.expand(pcoll)","handlingStrategy":"type-guard","validationCode":"if pcoll is None or pcoll.pipeline is None:\n    pcoll = active_pipeline | 'Recreate' >> beam.Create(source_items)","typeGuard":"def is_attached_pcollection(x):\n    return isinstance(x, pvalue.PCollection) and x.pipeline is not None","tryCatchPattern":"try:\n    my_transform.expand(pcoll)\nexcept error.TransformError as ex:\n    logger.error('PCollection not attached to a pipeline: %s', ex)\n    raise","preventionTips":["Build PCollections only through pipeline | transform","Avoid reusing outputs from discarded pipelines","Use TestPipeline in tests instead of manual construction"],"tags":["python","apache-beam","ptransform","pipeline-context"],"backgroundTag":"invalid-state-transition","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"}