{"record":{"id":"a7eafab8a942bee4","repo":"apache/beam","slug":"expected-a-ptransform-object-got-s","errorCode":null,"errorMessage":"Expected a PTransform object, got %s","messagePattern":"Expected a PTransform object, got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/pipeline.py","lineNumber":725,"sourceCode":"    with scoped_pipeline_options(self._options):\n      return self._apply_internal(transform, pvalueish, label)\n\n  def _apply_internal(\n      self,\n      transform: ptransform.PTransform,\n      pvalueish: Optional[pvalue.PValue] = None,\n      label: Optional[str] = None) -> pvalue.PValue:\n    \"\"\"Internal implementation of apply(), called within scoped options.\"\"\"\n    if isinstance(transform, ptransform._NamedPTransform):\n      return self.apply(\n          transform.transform, pvalueish, label or transform.label)\n\n    if not label and isinstance(transform, ptransform._PTransformFnPTransform):\n      # This must be set before label is inspected.\n      transform.set_options(self._options)\n\n    if not isinstance(transform, ptransform.PTransform):\n      raise TypeError(\"Expected a PTransform object, got %s\" % transform)\n\n    if label:\n      # Fix self.label as it is inspected by some PTransform operations\n      # (e.g. to produce error messages for type hint violations).\n      old_label, transform.label = transform.label, label\n      try:\n        return self.apply(transform, pvalueish)\n      finally:\n        transform.label = old_label\n\n    # Attempts to alter the label of the transform to be applied only when it's\n    # a top-level transform so that the cell number will not be prepended to\n    # every child transform in a composite.\n    if self._current_transform() is self._root_transform():\n      alter_label_if_ipython(transform, pvalueish)\n\n    full_label = '/'.join(\n        [self._current_transform().full_label, transform.label]).lstrip('/')","sourceCodeStart":707,"sourceCodeEnd":743,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/pipeline.py#L707-L743","documentation":"Pipeline.apply/_apply_internal requires the transform argument to be an instance of PTransform. Anything else (a function, class, string, None) cannot be applied to the pipeline, so a TypeError is raised naming the offending object.","triggerScenarios":"pipeline.apply(MyTransformClass) (class not instance), pipeline.apply(some_function), pipeline.apply('label', pcoll) with arguments in the wrong order, or passing the result of a factory that returned None.","commonSituations":"Forgetting parentheses when instantiating a transform; passing a plain function instead of wrapping it (e.g. beam.Map(fn)); mixing up apply's positional signature apply(transform, pvalueish, label).","solutions":["Instantiate the transform: apply(Map(fn)) not apply(Map).","Wrap plain functions in beam.Map/beam.FlatMap/beam.ParDo instead of passing them directly.","Check argument order: pipeline.apply(transform, pvalueish, label).","Verify the variable isn't None due to a failed factory/import."],"exampleFix":"// before\nresult = pipeline.apply(beam.Map)\n// after\nresult = pipeline.apply(beam.Map(lambda x: x * 2))","handlingStrategy":"type-guard","validationCode":"from apache_beam.transforms.ptransform import PTransform\nassert isinstance(my_transform, PTransform), 'not a PTransform instance'","typeGuard":"def is_ptransform(t) -> bool:\n    from apache_beam.transforms.ptransform import PTransform\n    return isinstance(t, PTransform)","tryCatchPattern":"try:\n    pipeline.apply(t, pcoll)\nexcept TypeError as e:\n    if 'Expected a PTransform' in str(e):\n        raise ValueError(f'wrap {t!r} in beam.Map/beam.ParDo') from e","preventionTips":["Instantiate transforms before applying","Wrap plain callables in beam.Map/FlatMap","Use pcoll | transform syntax to avoid argument-order mistakes"],"tags":["python","apache-beam","type-error","ptransform"],"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-20T03:17:13.778Z"}