Skip to content

Commit

Permalink
Avoid reordering add-on repositories on Backup load
Browse files Browse the repository at this point in the history
The `ensure_builtin_repositories` function uses a set to deduplicate
items, which sometimes led to a change of order in elements. This is
problematic when deduplicating Backups.

Simply avoid mangling the list of add-on repositories on load. Instead
rely on `update_repositories` which uses the same function to ensure
built-in repositories when loading the store configuration and restoring
a backup file.
  • Loading branch information
agners committed Jan 31, 2025
1 parent 30cbb03 commit dd7dd59
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions supervisor/backups/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ def folders(self) -> list[str]:

@property
def repositories(self) -> list[str]:
"""Return backup date."""
"""Return add-on store repositories."""
return self._data[ATTR_REPOSITORIES]

@repositories.setter
def repositories(self, value: list[str]) -> None:
"""Set backup date."""
"""Set add-on store repositories."""
self._data[ATTR_REPOSITORIES] = value

@property
Expand Down Expand Up @@ -286,7 +286,7 @@ def __eq__(self, other: Any) -> bool:
or k not in other._data
or self._data[k] != other._data[k]
):
_LOGGER.debug(
_LOGGER.info(
"Backup %s and %s not equal because %s field has different value: %s and %s",
self.slug,
other.slug,
Expand Down
17 changes: 10 additions & 7 deletions supervisor/store/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
)


def ensure_builtin_repositories(addon_repositories: list[str]) -> list[str]:
"""Ensure builtin repositories are in list.
Note: This should not be used in validation as the resulting list is not
stable. This can have side effects when comparing data later on.
"""
return list(set(addon_repositories) | BUILTIN_REPOSITORIES)


def validate_repository(repository: str) -> str:
"""Validate a valid repository."""
if repository in [StoreType.CORE, StoreType.LOCAL]:
Expand All @@ -44,13 +53,7 @@ def validate_repository(repository: str) -> str:
return repository


def ensure_builtin_repositories(addon_repositories: list[str]) -> list[str]:
"""Ensure builtin repositories are in list."""
return list(set(addon_repositories) | BUILTIN_REPOSITORIES)


# pylint: disable=no-value-for-parameter
repositories = vol.All([validate_repository], vol.Unique(), ensure_builtin_repositories)
repositories = vol.All([validate_repository], vol.Unique())

SCHEMA_STORE_FILE = vol.Schema(
{
Expand Down

0 comments on commit dd7dd59

Please sign in to comment.