{"record":{"id":"a1ab8b4a6a140422","repo":"apache/superset","slug":"annotation-layer-not-found-a1ab8b","errorCode":null,"errorMessage":"Annotation layer not found.","messagePattern":"Annotation layer not found\\.","errorType":"exception","errorClass":"AnnotationLayerNotFoundError","httpStatus":404,"severity":"error","filePath":"superset/commands/annotation_layer/annotation/update.py","lineNumber":66,"sourceCode":"    def run(self) -> Model:\n        self.validate()\n        assert self._model\n        return AnnotationDAO.update(self._model, self._properties)\n\n    def validate(self) -> None:\n        exceptions: list[ValidationError] = []\n        layer_id: Optional[int] = self._properties.get(\"layer\")\n        short_descr: str = self._properties.get(\"short_descr\", \"\")\n\n        # Validate/populate model exists\n        self._model = AnnotationDAO.find_by_id(self._model_id)\n        if not self._model:\n            raise AnnotationNotFoundError()\n        # Validate/populate layer exists\n        if layer_id:\n            annotation_layer = AnnotationLayerDAO.find_by_id(layer_id)\n            if not annotation_layer:\n                raise AnnotationLayerNotFoundError()\n            self._properties[\"layer\"] = annotation_layer\n\n            # Validate short descr uniqueness on this layer\n            if not AnnotationDAO.validate_update_uniqueness(\n                layer_id,\n                short_descr,\n                annotation_id=self._model_id,\n            ):\n                exceptions.append(AnnotationUniquenessValidationError())\n        else:\n            self._properties[\"layer\"] = self._model.layer\n\n        # validate date time sanity\n        start_dttm: Optional[datetime] = self._properties.get(\"start_dttm\")\n        end_dttm: Optional[datetime] = self._properties.get(\"end_dttm\")\n\n        if start_dttm and end_dttm and end_dttm < start_dttm:\n            exceptions.append(AnnotationDatesValidationError())","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/commands/annotation_layer/annotation/update.py#L48-L84","documentation":"AnnotationLayerNotFoundError raised inside UpdateAnnotationCommand.validate() (update.py:66): the PATCH payload includes a 'layer' id, but AnnotationLayerDAO.find_by_id(layer_id) returned None — the annotation is being moved to a layer that does not exist. HTTP 404. Note only a supplied layer triggers the lookup; omitting 'layer' keeps the current layer.","triggerScenarios":"PATCH /api/v1/annotation/<id> with {\"layer\": <deleted-or-foreign id>}; drag-and-drop move of an annotation to a layer removed moments earlier.","commonSituations":"Layer deleted concurrently while its annotations were being reorganized; ids copied between staging and prod; stale layer pickers.","solutions":["Verify the destination layer exists (GET /api/v1/annotation_layer/<id>) before including 'layer' in the PATCH.","If moving is optional, omit 'layer' from the payload to leave the annotation on its current layer.","Refresh layer options in the UI right before the move operation."],"exampleFix":"# before\nPATCH /api/v1/annotation/42 {\"layer\": 7}  # layer 7 deleted\n\n# after\nPATCH /api/v1/annotation/42 {\"short_descr\": \"renamed\"}  # keep current layer\n# or pick a live layer id after verifying via GET /api/v1/annotation_layer/","handlingStrategy":"validation","validationCode":"from superset.daos.annotation_layer import AnnotationLayerDAO\n\nif \"layer\" in properties:\n    assert AnnotationLayerDAO.find_by_id(properties[\"layer\"]) is not None, \"target layer missing\"","typeGuard":null,"tryCatchPattern":"try:\n    UpdateAnnotationCommand(model_id, properties).run()\nexcept AnnotationLayerNotFoundError:\n    layers = fetch_live_layers(); reselect_target_layer(layers)","preventionTips":["Confirm the destination layer via GET before moving an annotation.","Omit 'layer' from PATCH payloads when not moving the annotation.","Refresh layer pickers immediately before move operations."],"tags":["annotation","not-found","update","referential-integrity"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}