{"record":{"id":"2bafe44992fdf1fe","repo":"apache/beam","slug":"transform-full-label-expects-a-pcollection-as-input-got-a","errorCode":null,"errorMessage":"Transform '{full_label}' expects a PCollection as input. Got a PBegin/Pipeline instead.","messagePattern":"Transform '(.+?)' expects a PCollection as input\\. Got a PBegin/Pipeline instead\\.","errorType":"exception","errorClass":"TypeCheckError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/pipeline.py","lineNumber":806,"sourceCode":"\n    current = AppliedPTransform(\n        self._current_transform(),\n        transform,\n        full_label,\n        inputs,\n        None,\n        annotations=self._current_annotations())\n    self._current_transform().add_part(current)\n\n    try:\n      self.transforms_stack.append(current)\n\n      type_options = self._options.view_as(TypeOptions)\n      if type_options.pipeline_type_check:\n        transform.type_check_inputs(pvalueish)\n      if isinstance(pvalueish, pvalue.PBegin) and isinstance(transform, ParDo):\n        full_label = self._current_transform().full_label\n        raise TypeCheckError(\n            f\"Transform '{full_label}' expects a PCollection as input. \"\n            \"Got a PBegin/Pipeline instead.\")\n\n      self._assert_not_applying_PDone(pvalueish, transform)\n\n      pvalueish_result = self.runner.apply(transform, pvalueish, self._options)\n\n      if type_options is not None and type_options.pipeline_type_check:\n        transform.type_check_outputs(pvalueish_result)\n\n      for tag, result in ptransform.get_named_nested_pvalues(pvalueish_result):\n        assert isinstance(result, (pvalue.PValue, pvalue.DoOutputsTuple))\n\n        # Make sure we set the producer only for a leaf node in the transform\n        # DAG. This way we preserve the last transform of a composite transform\n        # as being the real producer of the result.\n        if result.producer is None:\n          result.producer = current","sourceCodeStart":788,"sourceCodeEnd":824,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/pipeline.py#L788-L824","documentation":"Beam forbids applying a ParDo directly to PBegin (the placeholder input of a Pipeline). A ParDo needs a real PCollection, so _apply_internal raises TypeCheckError with the transform's full label saying a PCollection was expected but a PBegin/Pipeline was given.","triggerScenarios":"pipeline | beam.Map(fn) or pipeline | beam.ParDo(...) applied straight to the Pipeline object instead of a PCollection; forgetting an initial Create/Read step.","commonSituations":"Typos where the first transform chains off `pipeline` instead of `pcoll`; refactoring that removed the source transform; examples that mistakenly start pipelines with a Map.","solutions":["Start the pipeline with a source: pipeline | beam.Create([...]) or a Read transform, then apply the ParDo.","Check the `|` chain starts from a PCollection, not the Pipeline.","If you meant a side effect/impulse, use pipeline | beam.Impulse() (which yields PBegin-compatible flow via a DoFn) carefully — generally use Create/Read."],"exampleFix":"// before\nresult = pipeline | beam.Map(lambda x: x * 2)\n// after\nresult = pipeline | beam.Create([1, 2, 3]) | beam.Map(lambda x: x * 2)","handlingStrategy":"type-guard","validationCode":"from apache_beam.pvalue import PBegin\ndef ensure_not_pbegin(x):\n    assert not isinstance(x, PBegin), 'ParDo needs a PCollection, not PBegin/Pipeline'","typeGuard":"from apache_beam.pvalue import PBegin, PCollection\ndef is_applyable_input(x) -> bool:\n    return isinstance(x, PCollection) and not isinstance(x, PBegin)","tryCatchPattern":"try:\n    out = pcoll_or_pipeline | beam.Map(fn)\nexcept TypeCheckError as e:\n    if 'PBegin/Pipeline' in str(e):\n        raise ValueError('chain from a PCollection; add beam.Create/Read first') from e","preventionTips":["Always start pipelines with a source (Create/Read)","Chain transforms from PCollections, never from the Pipeline object","Use pipeline | 'label' >> pattern carefully at the start of graphs"],"tags":["python","apache-beam","type-check","pbegin","pardo"],"backgroundTag":"incompatible-source-type","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"}