{"record":{"id":"2ff33dd3df2031f5","repo":"apache/beam","slug":"a-transform-with-label-s-already-exists-in-the-pipeline-to","errorCode":null,"errorMessage":"A transform with label \"%s\" already exists in the pipeline. To apply a transform with a specified label, write pvalue | \"label\" >> transform or use the option \"auto_unique_labels\" to automatically generate unique transform labels. Note \"auto_unique_labels\" could cause data loss when updating a pipeline or reloading the job state. This is not recommended for streaming jobs.","messagePattern":"A transform with label \"(.+?)\" already exists in the pipeline\\. To apply a transform with a specified label, write pvalue \\| \"label\" >> transform or use the option \"auto_unique_labels\" to automatically generate unique transform labels\\. Note \"auto_unique_labels\" could cause data loss when updating a pipeline or reloading the job state\\. This is not recommended for streaming jobs\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/pipeline.py","lineNumber":757,"sourceCode":"    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('/')\n    if full_label in self.applied_labels:\n      auto_unique_labels = self._options.view_as(\n          StandardOptions).auto_unique_labels\n      if auto_unique_labels:\n        # If auto_unique_labels is set, we will append a unique suffix to the\n        # label to make it unique.\n        logging.warning(\n            'Using --auto_unique_labels could cause data loss when '\n            'updating a pipeline or reloading the job state. '\n            'This is not recommended for streaming jobs.')\n        unique_label = self._generate_unique_label(transform)\n        return self.apply(transform, pvalueish, unique_label)\n      else:\n        raise RuntimeError(\n            'A transform with label \"%s\" already exists in the pipeline. '\n            'To apply a transform with a specified label, write '\n            'pvalue | \"label\" >> transform or use the option '\n            '\"auto_unique_labels\" to automatically generate unique '\n            'transform labels. Note \"auto_unique_labels\" '\n            'could cause data loss when updating a pipeline or '\n            'reloading the job state. This is not recommended for '\n            'streaming jobs.' % full_label)\n    self.applied_labels.add(full_label)\n\n    if pvalueish is None:\n      full_label = self._current_transform().full_label\n      raise TypeCheckError(\n          f'Transform \"{full_label}\" was applied to the output of '\n          f'an object of type None.')\n\n    pvalueish, inputs = transform._extract_input_pvalues(pvalueish)\n    try:","sourceCodeStart":739,"sourceCodeEnd":775,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/pipeline.py#L739-L775","documentation":"Transform labels in a pipeline must be unique. When applying a transform whose label is already used, and the auto_unique_labels option is off, Beam raises RuntimeError explaining how to either give an explicit unique label via the | 'label' >> transform syntax or enable auto_unique_labels (with a data-loss caveat for streaming/update use).","triggerScenarios":"Applying two transforms that resolve to the same default label (e.g. two unnamed beam.Map of the same function, or two Create/Impulse nodes) in the same pipeline; re-applying a transform to multiple outputs without renaming.","commonSituations":"Loops building multiple similar steps with identical default labels; reusing a pipeline object for multiple runs; applying the same named transform twice ('read' twice).","solutions":["Give each transform a unique label: pcoll | 'my_unique_label' >> MyTransform().","Enable the auto_unique_labels option to auto-generate unique labels (avoid for streaming/job-update).","Refactor loops to interpolate a distinct label per iteration.","Use fresh Pipeline objects instead of reusing one for multiple graph builds."],"exampleFix":"// before\nfor i in range(2):\n  pcoll = pcoll | beam.Map(lambda x: x + 1)  # duplicate label 'Map'\n// after\nfor i in range(2):\n  pcoll = pcoll | ('inc_%d' % i) >> beam.Map(lambda x: x + 1)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    pcoll = pcoll | label >> transform\nexcept RuntimeError as e:\n    if 'already exists in the pipeline' in str(e):\n        label = f'{label}_{uuid.uuid4().hex[:8]}'\n        pcoll = pcoll | label >> transform","preventionTips":["Always name transforms explicitly with | 'label' >>","Generate unique labels in loops","Avoid reusing a Pipeline object for multiple graph builds","Avoid auto_unique_labels for streaming jobs"],"tags":["python","apache-beam","runtime-error","duplicate-label"],"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-14T16:17:12.679Z"}