Skip to content

Handle recreated repository IDs - #5463

Open
hugo-brito wants to merge 2 commits into
hacs:mainfrom
hugo-brito:hugobrito-reconcile-stale-repository-id
Open

Handle recreated repository IDs#5463
hugo-brito wants to merge 2 commits into
hacs:mainfrom
hugo-brito:hugobrito-reconcile-stale-repository-id

Conversation

@hugo-brito

@hugo-brito hugo-brito commented Aug 8, 2026

Copy link
Copy Markdown

Summary

GitHub assigns a new ID when a repository is deleted and recreated. HACS kept the stored ID and failed while loading the catalog.

Use the catalog ID for the same repository name, keep installed/default state, and remove the stale ID on the next store write. IDs already assigned to another repository still raise an error.

Tests

Added coverage for restore order, persistence and restart, removed and archived repositories, repeated ID changes, and ID collisions. A 1,000-entry catalog test checks that unchanged entries do not run reconciliation.

Fixes #5461

Copilot AI lite review requested due to automatic review settings August 8, 2026 13:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request addresses a startup edge case where the local stored repository registry (.storage/hacs.repositories) can contain multiple GitHub repository IDs for the same repository slug (e.g., after a repo is deleted/recreated), which previously could lead to “duplicate IDs” warnings and later failures when merging with the live catalog.

Changes:

  • Add repository-ID reconciliation logic to merge same-slug repository entries into a single registry object while preserving installed/default state.
  • Adjust restore/registration flow to prefer restoring by stored ID first to avoid cross-applying data between same-slug entries.
  • Add targeted tests covering stale-ID reconciliation and rejection of ID collisions across different slugs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
custom_components/hacs/base.py Adds reconcile_repository_id() to consolidate duplicate same-slug repositories and remap to the live catalog ID while preserving state.
custom_components/hacs/utils/data.py Updates restore/unknown-registration flow to support reconciliation and avoid duplicate-ID warnings during restore.
tests/hacsbase/test_hacsbase_data.py Adds regression tests for stale ID reconciliation and for rejecting ID reuse across different slugs.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Replace stale stored IDs with the catalog ID while keeping repository state.
@hugo-brito
hugo-brito force-pushed the hugobrito-reconcile-stale-repository-id branch from eaf5512 to 6001d64 Compare August 8, 2026 17:41
@hugo-brito hugo-brito changed the title Reconcile stale repository IDs Handle recreated repository IDs Aug 8, 2026
@hugo-brito hugo-brito mentioned this pull request Aug 8, 2026
8 tasks
@hugo-brito

Copy link
Copy Markdown
Author

I reproduced CI locally against 3dacb0a:

  • full pre-commit matrix: passed
  • action container build: passed
  • Python 3.13/minimum Home Assistant: 442 passed
  • Python 3.14/Home Assistant dev: 442 passed

The missing API-usage snapshots are included. Could a maintainer approve the workflows and add pr: bugfix?

@hugo-brito

Copy link
Copy Markdown
Author

@ludeeus could you please have a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate IDs error

2 participants