apache/superset · error · AnnotationLayerNotFoundError

Annotation layer not found.

Error message

Annotation layer not found.

What it means

AnnotationLayerNotFoundError from DeleteAnnotationLayerCommand.validate() (delete.py:49): AnnotationLayerDAO.find_by_ids returned fewer layers than the requested ids — at least one layer id in the bulk DELETE does not exist. HTTP 404; the entire batch is rejected before the integrity check runs.

Source

Thrown at superset/commands/annotation_layer/delete.py:49

logger = logging.getLogger(__name__)


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

  1. Filter the id list to layers that still exist before deleting (find_by_ids / GET filter).
  2. Treat 404 on delete as already-done in clients.
  3. Re-fetch the layer list in the UI immediately before a bulk delete action.

Example fix

# before
DeleteAnnotationLayerCommand([1, 2, 77]).run()

# after
existing = AnnotationLayerDAO.find_by_ids([1, 2, 77])
if existing:
    DeleteAnnotationLayerCommand([m.id for m in existing]).run()
Defensive patterns

Strategy: validation

Validate before calling

from superset.daos.annotation_layer import AnnotationLayerDAO

live = [m.id for m in AnnotationLayerDAO.find_by_ids(ids)]
# delete only live ids; missing ids are already gone

Try / catch

try:
    DeleteAnnotationLayerCommand(ids).run()
except AnnotationLayerNotFoundError:
    log.info("some layers already deleted: %s", ids)  # idempotent success

Prevention

When it happens

Trigger: DELETE /api/v1/annotation_layer/ with [1,2,77] where 77 was already deleted; re-sending a bulk delete; deleting from a stale list after another admin removed a layer.

Common situations: Non-idempotent delete scripts; concurrent deletes from two sessions; environment id drift in automation.

Related errors


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