{"record":{"id":"f043d6a336db3322","repo":"BerriAI/litellm","slug":"error-deleting-attachment-from-db-e","errorCode":null,"errorMessage":"Error deleting attachment from DB: {e}","messagePattern":"Error deleting attachment from DB: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":500,"severity":"error","filePath":"litellm/proxy/policy_engine/attachment_registry.py","lineNumber":371,"sourceCode":"            # Get attachment before deleting\n            attachment: Final[LiteLLM_PolicyAttachmentTable | None] = await PolicyAttachmentRepository(\n                prisma_client\n            ).table.find_unique(where={\"attachment_id\": attachment_id})\n\n            if attachment is None:\n                raise Exception(f\"Attachment with ID {attachment_id} not found\")\n\n            # Delete from DB\n            await PolicyAttachmentRepository(prisma_client).table.delete(where={\"attachment_id\": attachment_id})\n\n            # Note: In-memory attachments don't have IDs, so we need to sync from DB\n            # to properly update in-memory state\n            await self.sync_attachments_from_db(prisma_client)\n\n            return {\"message\": f\"Attachment {attachment_id} deleted successfully\"}\n        except Exception as e:\n            verbose_proxy_logger.exception(\"Error deleting attachment from DB: %s\", e)\n            raise Exception(f\"Error deleting attachment from DB: {e}\")\n\n    async def get_attachment_by_id_from_db(\n        self,\n        attachment_id: str,\n        prisma_client: \"PrismaClient\",\n    ) -> PolicyAttachmentDBResponse | None:\n        \"\"\"\n        Get a policy attachment by ID from the database.\n\n        Args:\n            attachment_id: The ID of the attachment to retrieve\n            prisma_client: The Prisma client instance\n\n        Returns:\n            PolicyAttachmentDBResponse if found, None otherwise\n        \"\"\"\n        try:\n            attachment: Final[LiteLLM_PolicyAttachmentTable | None] = await PolicyAttachmentRepository(","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/policy_engine/attachment_registry.py#L353-L389","documentation":"Catch-all error from the policy attachment delete routine: a non-lookup failure (typically a Prisma/database error during find_unique or delete on the policy attachment table) was raised while deleting the attachment; the original exception is embedded in the message.","triggerScenarios":"Thrown at litellm/proxy/policy_engine/attachment_registry.py:371 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check database connectivity and logs for the underlying DB error, then retry the delete."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}