{"record":{"id":"ae0db93a9bf0029c","repo":"langgenius/dify","slug":"app-not-found-ae0db9","errorCode":null,"errorMessage":"App not found","messagePattern":"App not found","errorType":"http","errorClass":"NotFound","httpStatus":404,"severity":"error","filePath":"api/controllers/console/app/annotation.py","lineNumber":57,"sourceCode":"from libs.login import current_account_with_tenant, login_required\nfrom models.model import App\nfrom services.annotation_service import (\n    AppAnnotationService,\n    EnableAnnotationArgs,\n    UpdateAnnotationArgs,\n    UpdateAnnotationSettingArgs,\n    UpsertAnnotationArgs,\n)\nfrom services.app_ref_service import AppRef, AppRefService\n\n\ndef _get_app_ref(session: Session, app_id: str) -> AppRef:\n    _, current_tenant_id = current_account_with_tenant()\n    app = session.scalar(\n        select(App).where(App.id == app_id, App.tenant_id == current_tenant_id, App.status == \"normal\").limit(1)\n    )\n    if app is None:\n        raise NotFound(\"App not found\")\n    return AppRefService.create_app_ref(app)\n\n\nclass AnnotationReplyPayload(BaseModel):\n    score_threshold: float = Field(..., description=\"Score threshold for annotation matching\")\n    embedding_provider_name: str = Field(..., description=\"Embedding provider name\")\n    embedding_model_name: str = Field(..., description=\"Embedding model name\")\n\n\nclass AnnotationSettingUpdatePayload(BaseModel):\n    score_threshold: float = Field(..., description=\"Score threshold\")\n\n\nclass AnnotationListQuery(BaseModel):\n    page: int = Field(default=1, ge=1, description=\"Page number\")\n    limit: int = Field(default=20, ge=1, description=\"Page size\")\n    keyword: str = Field(default=\"\", description=\"Search keyword\")\n","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/app/annotation.py#L39-L75","documentation":"Raised as werkzeug NotFound (HTTP 404) from _get_app_ref: no App row matches the given app_id under the current tenant with status='normal'. The helper builds an AppRef for annotation endpoints and refuses to proceed for a missing, deleted, or wrong-tenant app. Note it filters on status='normal', so a disabled/deleted App also yields this.","triggerScenarios":"Calling any annotation endpoint that funnels through _get_app_ref (annotation settings, annotations list/create) with an app_id that does not exist, belongs to another tenant, or has status != 'normal' (e.g. soft-deleted).","commonSituations":"App was soft-deleted (status set to something other than 'normal'); cross-tenant app_id; stale client reference after the App was removed; app_id typo or copy from another environment.","solutions":["Confirm SELECT id, status, tenant_id FROM apps WHERE id=<app_id> returns a row with status='normal' for the caller's tenant.","If the App was soft-deleted, restore it to status='normal' or stop referencing it.","Ensure the calling account belongs to the tenant that owns the App.","Reload the App list in the console to obtain a current app_id."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"from sqlalchemy import select\nfrom models.model import App\n\ndef app_is_normal(session, app_id: str, tenant_id: str) -> bool:\n    return session.scalar(\n        select(App.id).where(\n            App.id == app_id, App.tenant_id == tenant_id, App.status == 'normal'\n        ).limit(1)\n    ) is not None","typeGuard":null,"tryCatchPattern":"from werkzeug.exceptions import NotFound\n\ntry:\n    call_annotation_endpoint(app_id=app_id)\nexcept NotFound as exc:\n    if 'App not found' in str(exc):\n        reload_app_list()\n    raise","preventionTips":["Stop referencing apps after they are soft-deleted (status != 'normal').","Reload the App list to obtain a current app_id before annotation work.","Confirm the calling account belongs to the App's tenant."],"tags":["annotation","app-not-found","tenant-scope","not-found"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}