Skip to content

Fix ZHA blocking minor version downgrades#171319

Merged
edenhaus merged 4 commits into
home-assistant:devfrom
TheJulianJES:tjj/zha-fix-minor-version-downgrade-guard
May 20, 2026
Merged

Fix ZHA blocking minor version downgrades#171319
edenhaus merged 4 commits into
home-assistant:devfrom
TheJulianJES:tjj/zha-fix-minor-version-downgrade-guard

Conversation

@TheJulianJES
Copy link
Copy Markdown
Member

Proposed change

This fixes a small issue where ZHA blocked setup of the integration if the user tried to downgrade from a potential future HA version with a higher MINOR_VERSION to HA Core 2026.5.3. Addresses a review comment in: #171164 (comment).

This is done by loosening the guard preventing downgrades (causing a MIGRATION_ERROR state if False is returned). Now, only major version downgrades are blocked, as is correct per the documentation, and how most other integrations handle this.

Coverage for that line is also added with two tests.

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:

Per the config flow migration docs, minor version bumps must be
backwards-compatible: a downgrade within the same major version should
still load. The previous guard compared the tuple
(version, minor_version) against the handler, which incorrectly turned
any minor downgrade into a MIGRATION_ERROR. Compare only the major
version so minor downgrades load as the contract requires.
Covers both sides of the contract:
- minor-version downgrade (MINOR_VERSION + 1) loads as LOADED
- major-version downgrade (VERSION + 1) fails with MIGRATION_ERROR
Copilot AI review requested due to automatic review settings May 19, 2026 13:48
@home-assistant home-assistant Bot added bugfix cla-signed has-tests 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 May 19, 2026
@home-assistant
Copy link
Copy Markdown
Contributor

Hey there @dmulcahey, @Adminiuga, @puddly, 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

This PR updates ZHA config entry migration so downgrades from future minor versions no longer block integration setup, while still blocking future major versions.

Changes:

  • Loosens the ZHA migration guard to reject only future major config entry versions.
  • Adds tests covering allowed minor-version downgrades and blocked major-version downgrades.

Reviewed changes

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

File Description
homeassistant/components/zha/__init__.py Updates migration downgrade guard to compare only major config entry versions.
tests/components/zha/test_init.py Adds regression coverage for minor and major downgrade behavior.

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.

Thanks for catching this!

I wonder: would it be better to be more explicit with blocking downgrades? I feel like returning False is easily overlooked but raise BlockDowngrade is obvious.

Comment thread tests/components/zha/test_init.py Outdated
- Parametrize the two cases into one test, matching the existing
  migration test style in the file.
- Assert version/minor_version are preserved in both paths to confirm
  the guard returns before mutating any state.
- Use MINOR_VERSION + delta instead of a magic literal in the
  major-downgrade case.
Copilot AI review requested due to automatic review settings May 19, 2026 15:18
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

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

@TheJulianJES TheJulianJES added this to the 2026.5.4 milestone May 19, 2026
@TheJulianJES
Copy link
Copy Markdown
Member Author

As the PR introducing the guard was included in 2026.5.3, I've also added this PR to the milestone now.
(But at the moment, it's more of a theoretical issue: if a future version bumps the minor version and the user then downgrades to exactly 2026.5.3, setup is blocked.)

@TheJulianJES TheJulianJES marked this pull request as ready for review May 19, 2026 15:24
@TheJulianJES TheJulianJES requested a review from dmulcahey as a code owner May 19, 2026 15:24
Copy link
Copy Markdown
Member

@edenhaus edenhaus left a comment

Choose a reason for hiding this comment

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

Thanks @TheJulianJES 👍

@edenhaus
Copy link
Copy Markdown
Member

As the PR introducing the guard was included in 2026.5.3, I've also added this PR to the milestone now. (But at the moment, it's more of a theoretical issue: if a future version bumps the minor version and the user then downgrades to exactly 2026.5.3, setup is blocked.)

Normally users will downgrade to the latest patch of a release. So it's theoretically but we cannot do nothing about it

@edenhaus edenhaus merged commit 162729a into home-assistant:dev May 20, 2026
33 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators May 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bugfix by-code-owner cla-signed has-tests 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