{"record":{"id":"051403437b150966","repo":"apache/superset","slug":"chart-with-id-annotation-layer-value-referen","errorCode":null,"errorMessage":"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.","messagePattern":"Chart with ID (.+?) \\(referenced by annotation layer '(.+?)'\\) was not found\\. Please verify that the chart exists and is accessible\\.","errorType":"validation","errorClass":"QueryObjectValidationError","httpStatus":400,"severity":"error","filePath":"superset/common/query_context_processor.py","lineNumber":672,"sourceCode":"            ]\n            layer_object = layer_objects[layer_id]\n            records = [\n                {column: getattr(annotation, column) for column in columns}\n                for annotation in layer_object.annotation\n            ]\n            result = {\"columns\": columns, \"records\": records}\n            annotation_data[layer_name] = result\n        return annotation_data\n\n    @staticmethod\n    def get_viz_annotation_data(  # noqa: C901\n        annotation_layer: dict[str, Any], force: bool\n    ) -> dict[str, Any]:\n        # pylint: disable=import-outside-toplevel\n        from superset.commands.chart.data.get_data_command import ChartDataCommand\n\n        if not (chart := ChartDAO.find_by_id(annotation_layer[\"value\"])):\n            raise QueryObjectValidationError(\n                _(\n                    f\"\"\"Chart with ID {annotation_layer[\"value\"]} (referenced by\n                    annotation layer '{annotation_layer[\"name\"]}') was not found.\n                    Please verify that the chart exists and is accessible.\"\"\"\n                )\n            )\n\n        try:\n            if not (query_context := chart.get_query_context()):\n                raise QueryObjectValidationError(\n                    _(\n                        f\"\"\"The query context for chart ID {chart.id} (referenced\n                        by annotation layer '{annotation_layer[\"name\"]}') was not found.\n                        Please ensure the chart is properly configured and has a valid\n                        query context.\"\"\"\n                    )\n                )\n","sourceCodeStart":654,"sourceCodeEnd":690,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/common/query_context_processor.py#L654-L690","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Open the chart's annotation configuration and re-select an existing chart (or remove the layer).","If exporting/importing, include the annotation-source chart in the bundle and fix its ID in the imported params.","Delete orphaned annotation layer entries from the chart's params JSON."],"exampleFix":"# before (chart params)\n\"annotation_layers\": [{\"name\": \"ref\", \"value\": 123, ...}]  # chart 123 deleted\n\n# after\n\"annotation_layers\": []  # or point value at an existing chart ID","handlingStrategy":"validation","validationCode":"from superset.daos.chart import ChartDAO\nlayer_ids = [l[\"value\"] for l in annotation_layers if l.get(\"sourceType\") == \"chart\"]\nmissing = [i for i in layer_ids if ChartDAO.find_by_id(i) is None]\nif missing:\n    drop_layers(missing)","typeGuard":"def layer_sources_exist(layers: list[dict]) -> bool:\n    return all(ChartDAO.find_by_id(l[\"value\"]) for l in chart_type_layers(layers))","tryCatchPattern":"except QueryObjectValidationError as e:\n    if \"referenced by annotation layer\" in str(e):\n        strip_bad_annotation_layers_from_params()","preventionTips":["When deleting charts, grep dependents' annotation layers","Import annotation-source charts with their consumers"],"tags":["annotations","chart","not-found","validation","backend"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}