{"record":{"id":"1481003b201524e5","repo":"BerriAI/litellm","slug":"litellm-managed-self-resource-type-with-id-unif","errorCode":null,"errorMessage":"LiteLLM Managed {self.resource_type} with id={unified_resource_id} not found","messagePattern":"LiteLLM Managed (.+?) with id=(.+?) not found","errorType":"exception","errorClass":"Exception","httpStatus":404,"severity":"error","filePath":"litellm/llms/base_llm/managed_resources/base_managed_resource.py","lineNumber":270,"sourceCode":"        unified_resource_id: str,\n        litellm_parent_otel_span: Span | None = None,\n    ) -> ResourceObjectType | None:\n        \"\"\"\n        Delete unified resource from cache and database.\n\n        Args:\n            unified_resource_id: The unified resource ID to delete\n            litellm_parent_otel_span: OpenTelemetry span for tracing\n\n        Returns:\n            The deleted resource object or None if not found\n        \"\"\"\n        # Get old value from database\n        table: Final = getattr(self.prisma_client.db, self.table_name)\n        initial_value: Final = await table.find_first(where={\"unified_resource_id\": unified_resource_id})\n\n        if initial_value is None:\n            raise Exception(f\"LiteLLM Managed {self.resource_type} with id={unified_resource_id} not found\")\n\n        # Delete from cache\n        await self.internal_usage_cache.async_set_cache(\n            key=unified_resource_id,\n            value=None,\n            litellm_parent_otel_span=litellm_parent_otel_span,\n        )\n\n        # Delete from database\n        await table.delete(where={\"unified_resource_id\": unified_resource_id})\n\n        return initial_value.resource_object\n\n    async def can_user_access_unified_resource_id(\n        self,\n        unified_resource_id: str,\n        user_api_key_dict: UserAPIKeyAuth,\n        litellm_parent_otel_span: Span | None = None,","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/base_llm/managed_resources/base_managed_resource.py#L252-L288","documentation":"Raised by BaseManagedResource.delete_resource (and similar managed-resource flows) when no row with the given unified_resource_id exists in the database before deletion. LiteLLM Managed resources (unified IDs across models) first read the current value; a missing row means the ID is wrong, already deleted, or scoped to another organization.","triggerScenarios":"DELETE on a managed resource endpoint with an expired/incorrect unified_resource_id; double-submit of the same delete request (second one finds nothing); resource created under a different org/user and deleted under another; stale ID cached in the client.","commonSituations":"Idempotent-delete assumptions: clients retrying deletes after timeout; UI holding stale IDs after another admin removed the resource; test runs against the wrong database instance.","solutions":["Re-list resources to get current unified_resource_ids and retry the delete with a fresh ID.","Make client deletes idempotent: treat 'not found' as success (catch and check the message).","Verify org/user scoping — the ID may exist but be invisible to the requesting tenant.","Check for concurrent deletions (audit log) before assuming data loss."],"exampleFix":"# before\nawait managed_resource.delete_resource(unified_resource_id=rid)  # raises on stale ID\n\n# after\ntry:\n    await managed_resource.delete_resource(unified_resource_id=rid)\nexcept Exception as e:\n    if 'not found' in str(e):\n        return  # already deleted; treat as success\n    raise","handlingStrategy":"try-catch","validationCode":"async def resource_exists(handler, unified_resource_id: str) -> bool:\n    return await handler.get_resource(unified_resource_id=unified_resource_id) is not None","typeGuard":null,"tryCatchPattern":"try:\n    await handler.delete_resource(unified_resource_id=rid)\nexcept Exception as e:\n    if 'not found' in str(e):\n        return {'deleted': False, 'reason': 'already-gone'}  # idempotent success\n    raise","preventionTips":["Treat deletes as idempotent in client logic; absorb 'not found'.","Refresh IDs from list endpoints immediately before delete operations.","Guard against double-submit in UIs (disable button, dedupe by request id)."],"tags":["managed-resources","delete","not-found","idempotency"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}