{"record":{"id":"9f0907c0f11d3fea","repo":"VectifyAI/PageIndex","slug":"failed-to-delete-document-document-not-found","errorCode":null,"errorMessage":"Failed to delete document: Document not found.","messagePattern":"Failed to delete document: Document not found\\.","errorType":"exception","errorClass":"PageIndexAPIError","httpStatus":null,"severity":"error","filePath":"pageindex/local_api.py","lineNumber":342,"sourceCode":"\n    # ── document management ──\n\n    def _require_doc(self, doc_id: str, error_prefix: str) -> dict:\n        meta = self._store.get_meta(doc_id)\n        if meta is None:\n            raise PageIndexAPIError(f\"{error_prefix}: Document not found.\")\n        return meta\n\n    def get_document(self, doc_id: str) -> dict[str, Any]:\n        meta = self._store.get_meta(doc_id)\n        if meta is None:\n            raise PageIndexAPIError(\"Failed to get document metadata: Document not found\")\n        return {key: meta.get(key) for key in\n                (\"id\", \"name\", \"description\", \"status\", \"createdAt\", \"pageNum\", \"folderId\")}\n\n    def delete_document(self, doc_id: str) -> dict[str, Any]:\n        if not self._store.delete_document(doc_id):\n            raise PageIndexAPIError(\"Failed to delete document: Document not found.\")\n        return {\"message\": \"Document deleted successfully.\"}\n\n    def list_documents(\n        self,\n        limit: int = 50,\n        offset: int = 0,\n        folder_id: str | None = None,\n    ) -> dict[str, Any]:\n        if limit < 1 or limit > 100:\n            raise ValueError(\"limit must be between 1 and 100\")\n        if offset < 0:\n            raise ValueError(\"offset must be non-negative\")\n        if folder_id is not None:\n            raise PageIndexAPIError(\n                \"Failed to list documents: folders are not supported in local mode.\"\n            )\n        metas = sorted(self._store.list_metas(), key=lambda m: m.get(\"id\") or \"\")\n        metas.sort(key=lambda m: m.get(\"createdAt\") or \"\", reverse=True)","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/VectifyAI/PageIndex/blob/afb5e119766630af6014b04fe8b53357527bc05e/pageindex/local_api.py#L324-L360","documentation":"Raised by PageIndexLocal.delete_document when the underlying store reports the delete failed, which in local mode means no document with that doc_id exists (already deleted, wrong ID, or store path mismatch). The local store is filesystem/index-backed, so a stale ID from a previous session or a different data directory will not resolve.","triggerScenarios":"Calling client.delete_document(doc_id) with an ID returned by a previous process run, an ID from another machine's store, or calling delete twice (second call raises).","commonSituations":"Retrying a delete after a network-looking failure, syncing IDs between environments, UI showing a stale document list, deleting after the store directory was recreated.","solutions":["Verify the ID exists first: client.get_document(doc_id) (or list_documents) before deleting","Treat 'not found' as success if the goal is absence: catch and ignore this specific error","Ensure all processes point at the same local store/data directory"],"exampleFix":"// before\nclient.delete_document(\"doc_123\")\n\n// after\ntry:\n    client.delete_document(\"doc_123\")\nexcept PageIndexAPIError:\n    pass  # already gone","handlingStrategy":"try-catch","validationCode":"try:\n    meta = client.get_document(doc_id)\nexcept PageIndexAPIError:\n    meta = None\nif meta is None:\n    skip_delete = True","typeGuard":"null","tryCatchPattern":"try:\n    client.delete_document(doc_id)\nexcept PageIndexAPIError as e:\n    if \"not found\" not in str(e).lower():\n        raise\n    # idempotent delete: treat as success","preventionTips":["Refresh document lists before showing delete actions","Cache doc IDs per store/data directory","Make deletes idempotent by swallowing not-found"],"tags":["pageindex","local-mode","delete","not-found","idempotency"],"backgroundTag":"resource-not-found","analyzedSha":"afb5e119766630af6014b04fe8b53357527bc05e","analyzedAt":"2026-08-27T11:20:48.519Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}