apache/superset · error · AnnotationLayerNotFoundError

Annotation layer not found.

Error message

Annotation layer not found.

What it means

AnnotationLayerNotFoundError from AnnotationLayerUpdateCommand.validate() (update.py:56): AnnotationLayerDAO.find_by_id(self._model_id) returned None — the layer being PATCHed does not exist. HTTP 404. Distinct from the 422 invalid error raised later in the same method for name uniqueness.

Source

Thrown at superset/commands/annotation_layer/update.py:56

class UpdateAnnotationLayerCommand(BaseCommand):
    def __init__(self, model_id: int, data: dict[str, Any]):
        self._model_id = model_id
        self._properties = data.copy()
        self._model: Optional[AnnotationLayer] = None

    @transaction(on_error=partial(on_error, reraise=AnnotationLayerUpdateFailedError))
    def run(self) -> Model:
        self.validate()
        assert self._model
        return AnnotationLayerDAO.update(self._model, self._properties)

    def validate(self) -> None:
        exceptions: list[ValidationError] = []
        name = self._properties.get("name", "")
        self._model = AnnotationLayerDAO.find_by_id(self._model_id)

        if not self._model:
            raise AnnotationLayerNotFoundError()

        if not AnnotationLayerDAO.validate_update_uniqueness(
            name, layer_id=self._model_id
        ):
            exceptions.append(AnnotationLayerNameUniquenessValidationError())

        if exceptions:
            raise AnnotationLayerInvalidError(exceptions=exceptions)

View on GitHub (pinned to f4587218dd)

Solutions

  1. GET /api/v1/annotation_layer/<id> to confirm existence before PATCH.
  2. If 404, refresh the layer list and reapply the change to a live layer.
  3. Guard automation with an existence check and skip/log on missing rows.

Example fix

# before
UpdateAnnotationLayerCommand(model_id=12, {"name": "New"}).run()

# after
from superset.daos.annotation_layer import AnnotationLayerDAO
if AnnotationLayerDAO.find_by_id(12) is None:
    log.warning("layer 12 missing; refresh and retry")
else:
    UpdateAnnotationLayerCommand(model_id=12, {"name": "New"}).run()
Defensive patterns

Strategy: validation

Validate before calling

from superset.daos.annotation_layer import AnnotationLayerDAO

if AnnotationLayerDAO.find_by_id(layer_id) is None:
    return {"error": f"layer {layer_id} not found"}, 404

Try / catch

try:
    UpdateAnnotationLayerCommand(model_id, properties).run()
except AnnotationLayerNotFoundError:
    refresh_layers(); return {"error": "layer deleted elsewhere"}, 404

Prevention

When it happens

Trigger: PATCH /api/v1/annotation_layer/<id> where the layer was deleted in another session; renaming from a stale list view; scripted updates against wrong environment ids.

Common situations: Concurrent layer management by multiple admins; long-lived settings pages; drift between staging and prod metadata databases.

Related errors


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