apache/superset · error · QueryObjectValidationError

Chart with ID {annotation_layer["value"]} (referenced by ann

Error message

Chart with ID {annotation_layer["value"]} (referenced by annotation layer '{annotation_layer["name"]}') was not found. Please verify that the chart exists and is accessible.

What it means

In get_viz_annotation_data, an annotation layer of type that references a chart resolves the chart via ChartDAO.find_by_id(annotation_layer['value']); if no chart row exists (or the value is wrong), QueryObjectValidationError is raised naming the layer and chart ID. This runs when annotation data is fetched as part of a chart data request.

Source

Thrown at superset/common/query_context_processor.py:672

            ]
            layer_object = layer_objects[layer_id]
            records = [
                {column: getattr(annotation, column) for column in columns}
                for annotation in layer_object.annotation
            ]
            result = {"columns": columns, "records": records}
            annotation_data[layer_name] = result
        return annotation_data

    @staticmethod
    def get_viz_annotation_data(  # noqa: C901
        annotation_layer: dict[str, Any], force: bool
    ) -> dict[str, Any]:
        # pylint: disable=import-outside-toplevel
        from superset.commands.chart.data.get_data_command import ChartDataCommand

        if not (chart := ChartDAO.find_by_id(annotation_layer["value"])):
            raise QueryObjectValidationError(
                _(
                    f"""Chart with ID {annotation_layer["value"]} (referenced by
                    annotation layer '{annotation_layer["name"]}') was not found.
                    Please verify that the chart exists and is accessible."""
                )
            )

        try:
            if not (query_context := chart.get_query_context()):
                raise QueryObjectValidationError(
                    _(
                        f"""The query context for chart ID {chart.id} (referenced
                        by annotation layer '{annotation_layer["name"]}') was not found.
                        Please ensure the chart is properly configured and has a valid
                        query context."""
                    )
                )

View on GitHub (pinned to f4587218dd)

Solutions

  1. Open the chart's annotation configuration and re-select an existing chart (or remove the layer).
  2. If exporting/importing, include the annotation-source chart in the bundle and fix its ID in the imported params.
  3. Delete orphaned annotation layer entries from the chart's params JSON.

Example fix

# before (chart params)
"annotation_layers": [{"name": "ref", "value": 123, ...}]  # chart 123 deleted

# after
"annotation_layers": []  # or point value at an existing chart ID
Defensive patterns

Strategy: validation

Validate before calling

from superset.daos.chart import ChartDAO
layer_ids = [l["value"] for l in annotation_layers if l.get("sourceType") == "chart"]
missing = [i for i in layer_ids if ChartDAO.find_by_id(i) is None]
if missing:
    drop_layers(missing)

Type guard

def layer_sources_exist(layers: list[dict]) -> bool:
    return all(ChartDAO.find_by_id(l["value"]) for l in chart_type_layers(layers))

Try / catch

except QueryObjectValidationError as e:
    if "referenced by annotation layer" in str(e):
        strip_bad_annotation_layers_from_params()

Prevention

When it happens

Trigger: A chart with an annotation layer configured to source data from another chart (chartId in the layer config) whose referenced chart was deleted or whose ID is invalid; annotation_layers passed in a query context payload with a bogus value.

Common situations: Deleting a chart that other charts use as an annotation source (Superset does not cascade-clean layer configs); exporting/importing charts where the annotation source chart was not included; manual edits to chart params JSON.

Related errors


AI-assisted analysis of apache/superset@f4587218dd (2026-08-14). Data as JSON: /api/errors/051403437b150966. Report an issue: GitHub.