apache/superset · error · AnnotationLayerDeleteIntegrityError
Annotation layer has associated annotations.
Error message
Annotation layer has associated annotations.
What it means
AnnotationLayerDeleteIntegrityError raised by DeleteAnnotationLayerCommand.validate() (delete.py:51) when AnnotationLayerDAO.has_annotations(model_ids) is true — you cannot delete an annotation layer that still has annotations attached. It is a referential-integrity guard, not a failure; HTTP 404-class CommandException but semantically a 409-style conflict.
Source
Thrown at superset/commands/annotation_layer/delete.py:51
class DeleteAnnotationLayerCommand(BaseCommand):
def __init__(self, model_ids: list[int]):
self._model_ids = model_ids
self._models: Optional[list[AnnotationLayer]] = None
@transaction(on_error=partial(on_error, reraise=AnnotationLayerDeleteFailedError))
def run(self) -> None:
self.validate()
assert self._models
AnnotationLayerDAO.delete(self._models)
def validate(self) -> None:
# Validate/populate model exists
self._models = AnnotationLayerDAO.find_by_ids(self._model_ids)
if not self._models or len(self._models) != len(self._model_ids):
raise AnnotationLayerNotFoundError()
if AnnotationLayerDAO.has_annotations(self._model_ids):
raise AnnotationLayerDeleteIntegrityError()
View on GitHub (pinned to f4587218dd)
Solutions
- List the layer's annotations (GET /api/v1/annotation/?q=(layer:<id>)) and DELETE them first.
- Alternatively move annotations to another layer via PATCH before deleting the layer.
- Only after the layer is empty, re-issue DELETE /api/v1/annotation_layer/<id>.
Example fix
# before
DeleteAnnotationLayerCommand([5]).run() # layer 5 still has annotations
# after
ann_ids = [a.id for a in AnnotationDAO.find_by_layer_id(5)]
if ann_ids:
DeleteAnnotationCommand(ann_ids).run()
DeleteAnnotationLayerCommand([5]).run() Defensive patterns
Strategy: validation
Validate before calling
from superset.daos.annotation_layer import AnnotationLayerDAO
if AnnotationLayerDAO.has_annotations(layer_ids):
blocking = {lid: fetch_annotation_count(lid) for lid in layer_ids}
return {"error": "delete or move annotations first", "layers": blocking}, 409 Try / catch
try:
DeleteAnnotationLayerCommand(ids).run()
except AnnotationLayerDeleteIntegrityError:
delete_or_move_annotations(ids); DeleteAnnotationLayerCommand(ids).run() Prevention
- Check has_annotations() before offering the delete-layer action in the UI.
- Show the layer's annotation count in the UI so users know what blocks deletion.
- Automate cleanup: delete child annotations (or PATCH them to a new layer) before deleting layers.
When it happens
Trigger: DELETE /api/v1/annotation_layer/<id> while annotations reference the layer (annotation.layer_id FK); bulk delete where any one layer in the list still has annotations.
Common situations: Trying to clean up layers without first removing or migrating their annotations; import scripts creating layers+annotations then attempting layer cleanup.
Related errors
- Annotation layer not found.
- Annotation layer parameters are invalid.
- Annotation layer not found.
- Annotation layer not found.
- Annotation layer parameters are invalid.
AI-assisted analysis of apache/superset@f4587218dd (2026-08-14).
Data as JSON: /api/errors/737ebd7ca94dce90.
Report an issue: GitHub.