Skip to content

Conversation

@karwosts
Copy link
Member

@karwosts karwosts commented Jul 30, 2025

Proposed change

https://discord.com/channels/330944238910963714/427516175237382144/1400225096441925733

When opening an options flow, we build a new schema with default values from the config_entry.

Normally we try to not mutate the original data_schema, but when opening the flow with a section that has a suggested_value, we accidentally overwrite part of the original data_schema for the options_flow.

That means any further instance of that options flow that is opened for different entities pick up the suggested value from the previous options flow that was opened, not populating it from their own config entry data.

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

Checklist

  • 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.

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 link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant home-assistant bot added bugfix cla-signed core small-pr PRs with less than 30 lines. labels Jul 30, 2025
@karwosts
Copy link
Member Author

karwosts commented Jul 31, 2025

Started looking at a fix for this, but ran out of time to finish, and I will be unavailable to continue on it for a few days.

This change did fix the linked issue when tested.

History_stats CI is a known issue.
Other two CI fails probably need to be looked at, not sure if this broke something or if the test is just not testing the right thing.

@emontnemery
Copy link
Contributor

emontnemery commented Jul 31, 2025

We need tests for this.
How long will you be unavailable for @karwosts ?

Edit: Tests are improved in the linked PR #149759

@karwosts
Copy link
Member Author

Monday at the earliest, though I don't want to promise anything.

@emontnemery emontnemery changed the title Fix config_flow sections Fix add_suggested_values_to_schema when the schema has sections Jul 31, 2025
@emontnemery emontnemery mentioned this pull request Jul 31, 2025
19 tasks
@emontnemery emontnemery marked this pull request as ready for review July 31, 2025 16:17
Copilot AI review requested due to automatic review settings July 31, 2025 16:17
@emontnemery emontnemery requested a review from a team as a code owner July 31, 2025 16:17
@emontnemery emontnemery added this to the 2025.8.0 milestone Jul 31, 2025
Copy link
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 fixes a bug in the add_suggested_values_to_schema function where the original data schema was being mutated when dealing with sections that have suggested values. This caused subsequent options flows for different entities to inherit suggested values from previously opened flows instead of populating from their own config entry data.

Key changes:

  • Fixed schema mutation by deep copying section objects and their schemas
  • Updated tests to verify the fix and remove assertions about the known bug
  • Added comprehensive schema comparison helper function

Reviewed Changes

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

File Description
homeassistant/data_entry_flow.py Fixed the mutation bug by properly copying section objects and their schemas
tests/test_data_entry_flow.py Updated tests to verify the fix, added schema comparison helper, and removed bug-related assertions
Comments suppressed due to low confidence (1)

tests/test_data_entry_flow.py:139

  • The function name compare_schemas is misleading since it performs assertions rather than returning a boolean comparison result. Consider renaming to assert_schemas_equal or verify_schemas_equal to better reflect its behavior.
    def compare_schemas(schema: vol.Schema, expected_schema: vol.Schema) -> bool:

@emontnemery emontnemery merged commit aa6b37b into home-assistant:dev Jul 31, 2025
48 checks passed
@karwosts karwosts deleted the fix-config_flow-sections branch July 31, 2025 19:01
@github-actions github-actions bot locked and limited conversation to collaborators Aug 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Availability template is copied to wrong entity's options flow

4 participants