Skip to content

Catch HomeAssistantError in ZHA migration retry loops#168420

Merged
TheJulianJES merged 1 commit intodevfrom
fix-retry-during-backup-in-radio-manager
Apr 17, 2026
Merged

Catch HomeAssistantError in ZHA migration retry loops#168420
TheJulianJES merged 1 commit intodevfrom
fix-retry-during-backup-in-radio-manager

Conversation

@agners
Copy link
Copy Markdown
Member

@agners agners commented Apr 17, 2026

Breaking change

Proposed change

The retry loops in async_initiate_migration (backup) and async_finish_migration (restore) only caught OSError, but connection failures can also surface as HomeAssistantError (e.g. wrapping a TimeoutError). Include it in both retries so transient connection issues are retried instead of aborting the migration.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

The retry loops in async_initiate_migration (backup) and
async_finish_migration (restore) only caught OSError, but connection
failures can also surface as HomeAssistantError (e.g. wrapping a
TimeoutError). Include it in both retries so transient connection
issues are retried instead of aborting the migration.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@agners agners requested a review from dmulcahey as a code owner April 17, 2026 10:24
@agners agners added the bugfix label Apr 17, 2026
@agners agners requested review from Adminiuga and puddly as code owners April 17, 2026 10:24
Copilot AI review requested due to automatic review settings April 17, 2026 10:24
@agners agners requested a review from TheJulianJES as a code owner April 17, 2026 10:24
@home-assistant home-assistant Bot added cla-signed integration: zha small-pr PRs with less than 30 lines. Top 100 Integration is ranked within the top 100 by usage Top 200 Integration is ranked within the top 200 by usage Top 50 Integration is ranked within the top 50 by usage labels Apr 17, 2026
@home-assistant
Copy link
Copy Markdown
Contributor

Hey there @dmulcahey, @Adminiuga, @puddly, @TheJulianJES, mind taking a look at this pull request as it has been labeled with an integration (zha) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of zha can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign zha Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Update ZHA multi-PAN migration retry loops to also retry when transient connection failures are surfaced as HomeAssistantError, preventing migrations from aborting prematurely.

Changes:

  • Catch HomeAssistantError alongside OSError when creating a backup in async_initiate_migration.
  • Catch HomeAssistantError alongside OSError when restoring a backup in async_finish_migration.

)
break
except OSError as err:
except (OSError, HomeAssistantError) as err:
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

Add a regression test that verifies HomeAssistantError is retried (and eventually re-raised) during backup creation, since the retry loop now explicitly catches it alongside OSError.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's only relevant for migrating to and from multi-PAN, which is no longer supported. I'm guessing we'll remove this migration soon/eventually, so not a big need to test this.

await self._radio_mgr.restore_backup(overwrite_ieee=True)
break
except OSError as err:
except (OSError, HomeAssistantError) as err:
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

Add a regression test that verifies HomeAssistantError is retried (and eventually re-raised) during backup restore, since the retry loop now explicitly catches it alongside OSError.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@puddly puddly left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks!

Copy link
Copy Markdown
Member

@TheJulianJES TheJulianJES left a comment

Choose a reason for hiding this comment

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

Thanks! Just curious because this is only relevant for migrating to and from the old multi-PAN stuff, did you run into this yourself or saw a report about it?

@TheJulianJES TheJulianJES merged commit 32a8344 into dev Apr 17, 2026
37 checks passed
@TheJulianJES TheJulianJES deleted the fix-retry-during-backup-in-radio-manager branch April 17, 2026 19:06
@agners
Copy link
Copy Markdown
Member Author

agners commented Apr 17, 2026

Thanks! Just curious because this is only relevant for migrating to and from the old multi-PAN stuff, did you run into this yourself or saw a report about it?

Run into it myself while testing #168431.

@github-actions github-actions Bot locked and limited conversation to collaborators Apr 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bugfix cla-signed integration: zha Quality Scale: No score small-pr PRs with less than 30 lines. Top 50 Integration is ranked within the top 50 by usage Top 100 Integration is ranked within the top 100 by usage Top 200 Integration is ranked within the top 200 by usage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants