{"record":{"id":"ad3e48a20707d7d4","repo":"apache/beam","slug":"f-ambiguous-transform-at-line-safelineloader-get-line","errorCode":null,"errorMessage":"f'Ambiguous transform at line {SafeLineLoader.get_line(transform_name)}: {transform_name}'","messagePattern":"f'Ambiguous transform at line (.+?): (.+?)'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/yaml/yaml_transform.py","lineNumber":168,"sourceCode":"\n  def get_transform_id_and_output_name(self, name):\n    if '.' in name:\n      transform_name, output = name.rsplit('.', 1)\n    else:\n      transform_name, output = name, None\n    return self.get_transform_id(transform_name), output\n\n  def get_transform_id(self, transform_name):\n    if transform_name in self._transforms_by_uuid:\n      return transform_name\n    else:\n      candidates = self._uuid_by_name[transform_name]\n      if not candidates:\n        raise ValueError(\n            f'Unknown transform at line '\n            f'{SafeLineLoader.get_line(transform_name)}: {transform_name}')\n      elif len(candidates) > 1:\n        raise ValueError(\n            f'Ambiguous transform at line '\n            f'{SafeLineLoader.get_line(transform_name)}: {transform_name}')\n      else:\n        return only_element(candidates)\n\n  def get_transform_spec(self, transform_name_or_id):\n    return self._transforms_by_uuid[self.get_transform_id(transform_name_or_id)]\n\n\nclass Scope(LightweightScope):\n  \"\"\"To look up PCollections (typically outputs of prior transforms) by name.\"\"\"\n  def __init__(\n      self,\n      root,\n      inputs: Mapping[str, Any],\n      transforms: Iterable[dict],\n      providers: Mapping[str, Iterable[yaml_provider.Provider]],\n      input_providers: Iterable[yaml_provider.Provider]):","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/yaml/yaml_transform.py#L150-L186","documentation":"LightweightScope.get_transform_id resolves a transform name to its unique id. When the pipeline YAML contains more than one transform sharing the same name (or type label), the name cannot be resolved unambiguously, so Beam raises this ValueError instead of silently picking one.","triggerScenarios":"Referencing a transform by name in an `input:` reference, via `get_transform_spec`, `followers`, `get_pcollection`, `get_outputs`, or `best_provider`, when two or more transforms in the pipeline spec declare the same `name` (or the same `type` string).","commonSituations":"Copy-pasting a transform block in the YAML without renaming it; generated pipelines that reuse names; using a bare type like `ReadFromBigQuery` as a reference while several transforms of that type exist.","solutions":["Give every transform in the pipeline a unique `name:` field.","Find the duplicate by searching the YAML for the reported name.","If the name was meant to select an output, reference it as `TransformName.output_tag` instead of relying on the transform name alone.","Use transform ids/line numbers from the message to disambiguate which blocks collide."],"exampleFix":"# before\n- name: parse\n  type: MapToFields\n  ...\n- name: parse\n  type: MapToFields\n  ...\n# after\n- name: parse_records\n  type: MapToFields\n  ...\n- name: parse_errors\n  type: MapToFields\n  ...","handlingStrategy":"validation","validationCode":"import collections\nnames = [t.get('name') for t in pipeline['transforms'] if t.get('name')]\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 is_unambiguous(specs, name):\n    matches = [t for t in specs if t.get('name') == name]\n    return len(matches) == 1","tryCatchPattern":"try:\n    tid = scope.get_transform_id(name)\nexcept ValueError as e:\n    if 'Ambiguous transform' in str(e):\n        candidates = [t for t in specs if t.get('name') == name]\n        tid = candidates[0]['__uuid__']","preventionTips":["Give every transform a unique name in pipeline YAML","Lint the YAML with a duplicate-name check before submitting","Never reference transforms by bare type name when multiple instances exist"],"tags":["yaml","beam-yaml","pipeline-definition","ambiguity"],"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"}