{"record":{"id":"524fdaf94b2e2361","repo":"apache/beam","slug":"label-does-not-exist-for-lineage","errorCode":null,"errorMessage":"Label {} does not exist for Lineage","messagePattern":"Label (.+?) does not exist for Lineage","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/metrics/metric.py","lineNumber":515,"sourceCode":"            *segments,\n            subtype=subtype,\n            last_segment_sep=last_segment_sep))\n\n  def add_raw(self, *rollup_segments: str) -> None:\n    \"\"\"Adds the given fqn as lineage.\n\n    `rollup_segments` should be an iterable of strings whose concatenation\n    is a valid Dataplex FQN.  In particular, this means they will often have\n    trailing delimiters.\n    \"\"\"\n    self.metric.add(rollup_segments)\n\n  @staticmethod\n  def query(results: MetricResults,\n            label: str,\n            truncated_marker: str = '*') -> set[str]:\n    if not label in Lineage._METRICS:\n      raise ValueError(\"Label {} does not exist for Lineage\", label)\n    response = results.query(\n        MetricsFilter().with_namespace(Lineage.LINEAGE_NAMESPACE).with_name(\n            label))[MetricResults.BOUNDED_TRIES]\n    result = set()\n    for metric in response:\n      for fqn in metric.committed.flattened():\n        result.add(''.join(fqn[:-1]) + (truncated_marker if fqn[-1] else ''))\n      for fqn in metric.attempted.flattened():\n        result.add(''.join(fqn[:-1]) + (truncated_marker if fqn[-1] else ''))\n    return result\n","sourceCodeStart":497,"sourceCodeEnd":526,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/metrics/metric.py#L497-L526","documentation":"Lineage.query() only accepts labels registered in Lineage._METRICS (the known lineage metric names). Passing an unknown label raises ValueError; note the message also uses comma-style formatting ('ValueError(\"Label {} ...\", label)') so the label placeholder is not substituted.","triggerScenarios":"Calling Lineage.query(results, 'source_code_branch') with a label not among Lineage's supported lineage metrics (e.g. SOURCE_CODE_BRANCH, SOURCE_CODE_REVISION, or a typo of one).","commonSituations":"Custom lineage/observability queries guessing label names; renamed or newly added lineage labels not present in the installed Beam version.","solutions":["Use one of the labels defined in Lineage._METRICS (check the Lineage class in apache_beam/metrics/metric.py).","Inspect Lineage._METRICS at runtime to enumerate valid labels before querying.","Upgrade Beam if the label you need was added in a newer version."],"exampleFix":"- Lineage.query(results, 'source')\n+ from apache_beam.metrics.metric import Lineage\n+ assert 'SOURCE_CODE_BRANCH' in Lineage._METRICS\n+ Lineage.query(results, 'SOURCE_CODE_BRANCH')","handlingStrategy":"validation","validationCode":"from apache_beam.metrics.metric import Lineage\nassert label in Lineage._METRICS, f'valid labels: {Lineage._METRICS}'","typeGuard":"def is_lineage_label(label):\n    from apache_beam.metrics.metric import Lineage\n    return label in Lineage._METRICS","tryCatchPattern":"try:\n    out = Lineage.query(results, label)\nexcept ValueError:\n    logger.error('unknown lineage label %r, valid: %s', label, Lineage._METRICS)","preventionTips":["Source labels from Lineage._METRICS instead of hardcoding strings.","Check the installed Beam version's Lineage class for the exact label names.","Avoid copy-pasting label names across Beam versions without verifying them."],"tags":["python","apache-beam","lineage","invalid-label"],"backgroundTag":"invalid-enum-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"}