{"record":{"id":"f4d76d4a0f6a835b","repo":"home-assistant/core","slug":"backup-backup-id-does-not-exist","errorCode":null,"errorMessage":"Backup {backup_id} does not exist","messagePattern":"Backup (.+?) does not exist","errorType":"exception","errorClass":"BackupNotFound","httpStatus":null,"severity":"error","filePath":"homeassistant/components/backup/backup.py","lineNumber":132,"sourceCode":"                ),\n                backup.backup_id,\n                backup_path,\n            )\n            self._backups.pop(backup_id)\n            raise BackupNotFound(f\"Backup {backup_id} not found\")\n\n        return backup\n\n    @override\n    def get_backup_path(self, backup_id: str) -> Path:\n        \"\"\"Return the local path to an existing backup.\n\n        Raises BackupAgentError if the backup does not exist.\n        \"\"\"\n        try:\n            return self._backups[backup_id][1]\n        except KeyError as err:\n            raise BackupNotFound(f\"Backup {backup_id} does not exist\") from err\n\n    @override\n    def get_new_backup_path(self, backup: AgentBackup) -> Path:\n        \"\"\"Return the local path to a new backup.\"\"\"\n        candidate = self._backup_dir / suggested_filename(backup)\n        # suggested_filename does not strip separators; refuse paths that would\n        # land outside the backup directory.\n        if candidate.parent != self._backup_dir:\n            raise InvalidBackupFilename(\n                f\"Refusing to write outside {self._backup_dir}: {candidate}\"\n            )\n        return candidate\n\n    @override\n    async def async_delete_backup(self, backup_id: str, **kwargs: Any) -> None:\n        \"\"\"Delete a backup file.\"\"\"\n        if not self._loaded_backups:\n            await self._load_backups()","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/home-assistant/core/blob/58a3fdb3ea0538617f0a07efcfba6294de64fd59/homeassistant/components/backup/backup.py#L114-L150","documentation":"Raised by LocalBackupAgent.get_backup_path when the requested backup_id has no entry in the _backups map (KeyError). get_backup_path is the synchronous path-lookup used by delete/restore flows, so this means the local agent has no tracked backup with that ID at all.","triggerScenarios":"Calling get_backup_path(backup_id) with an unknown ID — e.g., async_delete_backup on the local agent for a backup that was never loaded (the method forces _load_backups first, so the ID truly is absent), or an ID belonging to another agent.","commonSituations":"Deleting a backup entry from the UI after the file was already removed externally; scripts calling the websocket/API delete endpoint with a stale or foreign backup_id; race where the backup was deleted concurrently.","solutions":["Refresh the backup list and retry with the current backup_id from the refreshed list.","Ensure you target the agent that actually holds the backup (manager.sync_agents / per-agent lookups).","Catch BackupNotFound and treat 'already gone' as success for delete-style flows."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"tracked = local_agent._backups if False else None\n# public-safe variant: list first\nbackups = await local_agent.async_list_backups()\nif backup_id not in {b.backup_id for b in backups}:\n    LOGGER.info(\"backup %s unknown to local agent\", backup_id)","typeGuard":null,"tryCatchPattern":"from homeassistant.components.backup.agent import BackupNotFound\n\ntry:\n    path = local_agent.get_backup_path(backup_id)\nexcept BackupNotFound:\n    LOGGER.info(\"%s already gone; nothing to delete\", backup_id)\n    return  # idempotent delete","preventionTips":["Make delete flows idempotent: swallow BackupNotFound as success.","Always resolve IDs from a fresh async_list_backups result.","Target the owning agent, not always the local agent."],"tags":["backup","local-agent","not-found","keyerror"],"backgroundTag":null,"analyzedSha":"58a3fdb3ea0538617f0a07efcfba6294de64fd59","analyzedAt":"2026-08-14T20:54:38.818Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}