{"record":{"id":"3f3063ebca11dcc2","repo":"langflow-ai/langflow","slug":"error-deleting-knowledge-base","errorCode":null,"errorMessage":"Error deleting knowledge base.","messagePattern":"Error deleting knowledge base\\.","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"src/backend/base/langflow/api/v1/knowledge_bases.py","lineNumber":2100,"sourceCode":"\n        remote_warning = await _delete_remote_backend_collection(\n            kb_name=kb_name,\n            kb_path=kb_path,\n            current_user=kb_owner,\n        )\n\n        # Delete the DB row first, then attempt to clear the on-disk dir.\n        # Rationale: when Chroma still holds a SQLite lock (most common on\n        # Windows) physical removal can fail, but the user's intent was to\n        # remove the KB.  By dropping the DB row first the row never lingers\n        # past a partial cleanup, and KBStorageHelper.delete_storage() drops\n        # a sentinel inside any dir it could not remove so the listing layer\n        # treats it as gone until the next restart fully reaps it.\n        try:\n            await knowledge_base_service.delete_by_user_and_name(_kb_guard.owner_user.id, kb_name)\n        except Exception as exc:\n            await logger.aerror(\"KB DB delete failed for %s: %s\", kb_name, exc)\n            raise HTTPException(status_code=500, detail=\"Error deleting knowledge base.\") from exc\n\n        storage_warning: str | None = None\n        if not KBStorageHelper.delete_storage(kb_path, kb_name):\n            # Both physical removal AND the sentinel write failed.  This is\n            # rare (would require the dir itself being unwritable) but we\n            # still return 200 because the DB row is gone -- the user no\n            # longer sees the KB.  A warning surfaces so operators know the\n            # bytes are still on disk and want a follow-up cleanup.\n            storage_warning = (\n                f\"Knowledge base '{kb_name}' was removed from the database but its on-disk \"\n                \"files could not be cleaned up. The KB will not reappear in the UI; the bytes \"\n                \"will be removed on the next server restart.\"\n            )\n            await logger.awarning(storage_warning)\n\n    except HTTPException:\n        raise\n    except Exception as e:","sourceCodeStart":2082,"sourceCodeEnd":2118,"githubUrl":"https://github.com/langflow-ai/langflow/blob/976ec789d2886a86de109c044d089d68e96c9a35/src/backend/base/langflow/api/v1/knowledge_bases.py#L2082-L2118","documentation":"500 from DELETE /api/v1/knowledge_bases/{kb_name} when deleting the database row fails. The handler deliberately deletes the DB row first (so a partially-deleted KB never lingers), and if knowledge_base_service.delete_by_user_and_name raises, it logs 'KB DB delete failed for <kb>: <exc>' and returns this 500. Storage cleanup is NOT attempted in this path — the failure happened before it.","triggerScenarios":"DELETE /{kb_name} while the database is unavailable, locked, or the delete statement violates a constraint (e.g. dependent rows); transient DB connection drops mid-request.","commonSituations":"Another process holding a DB lock (long-running ingestion writing run rows), DB connection pool exhausted, network blip to a remote Postgres/MySQL.","solutions":["Check the server log for 'KB DB delete failed for ...' — the exception identifies the DB-level cause","Retry after any concurrent ingestion/cancel on the KB finishes (locks clear)","Verify DB connectivity and connection-pool health","If persistent, inspect for FK constraints or orphaned rows blocking the delete"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for attempt in range(3):\n    try:\n        await client.delete(f\"/api/v1/knowledge_bases/{kb_name}\")\n        break\n    except httpx.HTTPStatusError as e:\n        if e.response.status_code == 500 and attempt < 2:\n            await asyncio.sleep(2 ** attempt)  # DB lock likely transient\n            continue\n        raise","preventionTips":["Avoid deleting a KB while an ingestion/cancel for it is in flight","Monitor DB lock and connection-pool metrics","Distinguish this DB-failure 500 from the catch-all 500 by checking whether a retry then returns 404 (row already gone)"],"tags":["knowledge-base","delete","database","http-500","langflow"],"backgroundTag":null,"analyzedSha":"976ec789d2886a86de109c044d089d68e96c9a35","analyzedAt":"2026-08-14T18:23:12.227Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}