-
-
Notifications
You must be signed in to change notification settings - Fork 35.8k
Fix add_suggested_values_to_schema when the schema has sections
#149718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix add_suggested_values_to_schema when the schema has sections
#149718
Conversation
|
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. |
|
Monday at the earliest, though I don't want to promise anything. |
add_suggested_values_to_schema when the schema has sections
There was a problem hiding this 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_schemasis misleading since it performs assertions rather than returning a boolean comparison result. Consider renaming toassert_schemas_equalorverify_schemas_equalto better reflect its behavior.
def compare_schemas(schema: vol.Schema, expected_schema: vol.Schema) -> bool:
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
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: