{"record":{"id":"5fa16234218edd80","repo":"apache/beam","slug":"duplicate-name-at-identify-object-spec-name","errorCode":null,"errorMessage":"Duplicate name at {identify_object(spec)}: {name}","messagePattern":"Duplicate name at (.+?): (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"sdks/python/apache_beam/yaml/yaml_transform.py","lineNumber":469,"sourceCode":"      else:\n        msg = str(exn)\n      raise ValueError(\n          f'Invalid transform specification at {identify_object(spec)}: {msg}'\n      ) from exn\n\n  def unique_name(self, spec, ptransform, strictness=0):\n    if 'name' in spec:\n      name = spec['name']\n      strictness += 1\n    elif ('ExternalTransform' not in ptransform.label and\n          not ptransform.label.startswith('_')):\n      # The label may have interesting information.\n      name = ptransform.label\n    else:\n      name = spec['type']\n    if name in self._seen_names:\n      if strictness >= 2:\n        raise ValueError(f'Duplicate name at {identify_object(spec)}: {name}')\n      else:\n        name = f'{name}@{SafeLineLoader.get_line(spec)}'\n    self._seen_names.add(name)\n    return name\n\n\ndef expand_transform(spec, scope):\n  if 'type' not in spec:\n    raise TypeError(\n        f'Missing type parameter for transform at {identify_object(spec)}')\n  type = spec['type']\n  if type == 'composite':\n    return expand_composite_transform(spec, scope)\n  else:\n    return expand_leaf_transform(spec, scope)\n\n\ndef expand_leaf_transform(spec, scope):","sourceCodeStart":451,"sourceCodeEnd":487,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/yaml/yaml_transform.py#L451-L487","documentation":"Scope.unique_name assigns each PTransform a unique graph label. If a name was already seen, strictness >= 2 raises 'Duplicate name'; at lower strictness it silently disambiguates by appending @line. This error appears when strict duplicate checking is enabled and two transforms share a name.","triggerScenarios":"unique_name (invoked during create_ptransform naming) receives a spec whose `name` (or fallback type label) already exists in `self._seen_names`, with strictness >= 2 — e.g. validation passes that enforce strict naming.","commonSituations":"Copy-pasted YAML blocks with identical names; generated pipelines looping without unique suffixes; relying on the lenient @line rename while running strict validation; a transform name colliding with a type label.","solutions":["Rename one of the duplicate transforms so all names are unique.","Add line numbers/ids programmatically when generating specs.","Lower naming strictness if @line-suffixed duplicates are acceptable.","Audit generated pipelines for template loops reusing a fixed name."],"exampleFix":"# before\n- name: write_output\n  type: WriteToJson\n  ...\n- name: write_output\n  type: WriteToJson\n  ...\n# after\n- name: write_output_json\n  type: WriteToJson\n  ...\n- name: write_output_csv\n  type: WriteToJson\n  ...","handlingStrategy":"validation","validationCode":"import collections\nnames = [t.get('name', t['type']) for t in pipeline['transforms']]\ndups = [n for n, c in collections.Counter(names).items() if c > 1]\nif dups:\n    raise ValueError(f'Duplicate transform names: {dups}')","typeGuard":"def names_are_unique(specs):\n    seen = set()\n    for s in specs:\n        n = s.get('name', s.get('type'))\n        if n in seen:\n            return False\n        seen.add(n)\n    return True","tryCatchPattern":"try:\n    run_pipeline(spec, strict_naming=True)\nexcept ValueError as e:\n    if 'Duplicate name' in str(e):\n        raise UserPipelineError('Rename one of the duplicated transforms') from e","preventionTips":["Generate unique names with counters/suffixes in generated pipelines","Avoid copy-pasting transform blocks without renaming","Keep strict-naming validation in CI to catch duplicates early"],"tags":["yaml","beam-yaml","pipeline-definition","naming"],"backgroundTag":"invalid-identifier-format","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"}