{"record":{"id":"f560290fd3b8fd72","repo":"apache/beam","slug":"too-many-matches","errorCode":null,"errorMessage":"Too many matches","messagePattern":"Too many matches","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"sdks/python/apache_beam/runners/dataflow/dataflow_metrics.py","lineNumber":54,"sourceCode":"from apache_beam.metrics.metric import MetricResults\nfrom apache_beam.metrics.metricbase import MetricName\nfrom apache_beam.options.pipeline_options import GoogleCloudOptions\nfrom apache_beam.options.pipeline_options import PipelineOptions\n\n_LOGGER = logging.getLogger(__name__)\n\n\ndef _get_match(proto, filter_fn):\n  \"\"\"Finds and returns the first element that matches a query.\n\n  If no element matches the query, it throws ValueError.\n  If more than one element matches the query, it returns only the first.\n  \"\"\"\n  query = [elm for elm in proto if filter_fn(elm)]\n  if len(query) == 0:\n    raise ValueError('Could not find element')\n  elif len(query) > 1:\n    raise ValueError('Too many matches')\n\n  return query[0]\n\n\n# V1b3 MetricStructuredName keys to accept and copy to the MetricKey labels.\nSTRUCTURED_NAME_LABELS = set(\n    ['execution_step', 'original_name', 'output_user_name'])\n\n\nclass DataflowMetrics(MetricResults):\n  \"\"\"Implementation of MetricResults class for the Dataflow runner.\"\"\"\n  def __init__(self, dataflow_client=None, job_result=None, job_graph=None):\n    \"\"\"Initialize the Dataflow metrics object.\n\n    Args:\n      dataflow_client: apiclient.DataflowApplicationClient to interact with the\n        dataflow service.\n      job_result: DataflowPipelineResult with the state and id information of","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/runners/dataflow/dataflow_metrics.py#L36-L72","documentation":"Internal helper _get_match in the Dataflow metrics reader found more protos matching the query than the caller's single-match expectation allows (e.g. a step-name translation matching multiple job steps), making the result ambiguous; despite the docstring promising the first match, this strict check raises.","triggerScenarios":"`_translate_step_name` searches job_graph.proto.steps for x.name == internal_name and the job graph contains duplicate step names — possible with duplicated transform names in the submitted pipeline proto.","commonSituations":"Pipelines with repeated composite naming leading to identical internal step names in the proto, causing step-name translation to blow up instead of returning the first match.","solutions":["Ensure unique step/transform names when building the pipeline (avoid reusing names in composites).","Catch ValueError in query/translation code and skip translation for that key.","Fix or regenerate the job graph so proto step names are unique."],"exampleFix":"# before\nuser_step = metrics._translate_step_name(internal_name)\n# after\ntry:\n    user_step = metrics._translate_step_name(internal_name)\nexcept ValueError:\n    user_step = internal_name  # ambiguous or unknown step","handlingStrategy":"try-catch","validationCode":"from collections import Counter\nc = Counter(s.name for s in job_graph.proto.steps)\ndups = [n for n, k in c.items() if k > 1]\nif dups:\n    raise ValueError(f'Duplicate step names: {dups}')","typeGuard":null,"tryCatchPattern":"try:\n    user_name = metrics._translate_step_name(internal_name)\nexcept ValueError as e:\n    if 'Too many matches' in str(e):\n        user_name = internal_name  # ambiguous\n    raise","preventionTips":["Keep transform/step names unique in your pipeline.","Deduplicate step-name checks before translation.","Catch both _get_match errors uniformly in translation callers."],"tags":["python","apache-beam","dataflow","metrics"],"backgroundTag":"unexpected-response-shape","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"}