Make backup listing more resilient for onedrive (#143010)

Co-authored-by: Erwin Douna <e.douna@gmail.com>
This commit is contained in:
Josef Zweck 2025-04-22 13:36:59 +02:00 committed by GitHub
parent 8a084599d8
commit 159e55296f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 3 deletions

View File

@ -235,8 +235,12 @@ class OneDriveBackupAgent(BackupAgent):
items = await self._client.list_drive_items(self._folder_id)
async def download_backup_metadata(item_id: str) -> AgentBackup:
async def download_backup_metadata(item_id: str) -> AgentBackup | None:
try:
metadata_stream = await self._client.download_drive_item(item_id)
except OneDriveException as err:
_LOGGER.warning("Error downloading metadata for %s: %s", item_id, err)
return None
metadata_json = loads(await metadata_stream.read())
return AgentBackup.from_dict(metadata_json)
@ -246,6 +250,8 @@ class OneDriveBackupAgent(BackupAgent):
metadata_description_json := unescape(item.description)
):
backup = await download_backup_metadata(item.id)
if backup is None:
continue
metadata_description = loads(metadata_description_json)
backups[backup.backup_id] = OneDriveBackup(
backup=backup,

View File

@ -75,7 +75,6 @@ async def test_agents_info(
async def test_agents_list_backups(
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
mock_config_entry: MockConfigEntry,
) -> None:
"""Test agent list backups."""
@ -105,6 +104,22 @@ async def test_agents_list_backups(
]
async def test_agents_list_backups_with_download_failure(
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
mock_onedrive_client: MagicMock,
) -> None:
"""Test agent list backups still works if one of the items fails to download."""
mock_onedrive_client.download_drive_item.side_effect = OneDriveException("test")
client = await hass_ws_client(hass)
await client.send_json_auto_id({"type": "backup/info"})
response = await client.receive_json()
assert response["success"]
assert response["result"]["agent_errors"] == {}
assert response["result"]["backups"] == []
async def test_agents_get_backup(
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,