Protect mutable allowed_context_keys attribute in Selector classes - #181449
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The base initializer clears all specialized mappings, causing valid selector contexts to fail validation.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Moves selector context-key mappings from shared class attributes to per-instance state.
Changes:
- Initializes default context keys per selector instance.
- Relocates specialized mappings into three selector constructors.
File summaries
| File | Description |
|---|---|
homeassistant/helpers/selector.py |
Refactors allowed_context_keys initialization. |
Review details
Suppressed comments (1)
homeassistant/helpers/selector.py:445
- Add a regression test that verifies each affected selector retains its expected
allowed_context_keysand that mutating one instance does not affect another; the existing schema tests do not exercise this new behavior.
self.allowed_context_keys = {
# Filters the available attributes based on the selected entity
"filter_entity": {"entity"}
}
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
🟡 Changes recommended
The new isolation behavior lacks regression coverage.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Balanced
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The test permanently pollutes the process-wide selector registry with a fake entry.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
EetuPelkonen
left a comment
There was a problem hiding this comment.
Copilot has the order backwards: all three constructors call super().init() before assigning, so nothing gets wiped. I applied this and hassfest is 0 invalid over 1515 integrations, test_selector 234 passed. The other three comments are stale.
The issue that is solved here is the previous initialization of a mutable object. As it might be set in the subclass this mifht cause issues when a subclass changes the property. |
* upstream/dev: (792 commits) Add missing LitterHopper statuses to Whisker hopper status sensor (home-assistant#181342) Add configurable EnergyZero electricity price interval (home-assistant#181530) Bump nhc to 0.8.1 for Niko Home Control (home-assistant#181584) Bump aioskybell to 23.12.0 (home-assistant#181587) Protect mutable allowed_context_keys attribute in Selector classes (home-assistant#181449) Set easyEnergy quality scale to platinum (home-assistant#181378) Bump pyblackbird to 0.10 (home-assistant#181565) Bump vizaio to 0.7.0 (home-assistant#181568) Describe Z-Wave JS triggers for the automation editor (home-assistant#181129) Add ScorpionTrack last reported sensor (home-assistant#178755) Fix llama.cpp streaming capability reporting (home-assistant#179886) Report the Weheat cooling start conditions (home-assistant#181287) Fix swallowed exceptions in action handlers for Huawei LTE (home-assistant#181538) Fix swallowed exceptions in action handlers for ColorExtractor (home-assistant#181537) Add binary_sensor platform to NeoPool (home-assistant#180393) Bump vizaio to 0.6.2 (home-assistant#181562) Handle reauth_successful centrally (home-assistant#181154) Fix Vizio soundbars requiring authentication (home-assistant#181556) Update zizmor (home-assistant#181494) Fix lingering tasks in insteon properties and config tests (home-assistant#181555) ... # Conflicts: # homeassistant/components/vizio/manifest.json
* zwave-js-conditions: (1009 commits) Target Z-Wave JS condition nodes with a device selector Import the Z-Wave JS bypass helper from its new home in the trigger tests Add missing LitterHopper statuses to Whisker hopper status sensor (home-assistant#181342) Add configurable EnergyZero electricity price interval (home-assistant#181530) Bump nhc to 0.8.1 for Niko Home Control (home-assistant#181584) Bump aioskybell to 23.12.0 (home-assistant#181587) Protect mutable allowed_context_keys attribute in Selector classes (home-assistant#181449) Set easyEnergy quality scale to platinum (home-assistant#181378) Bump pyblackbird to 0.10 (home-assistant#181565) Bump vizaio to 0.7.0 (home-assistant#181568) Describe Z-Wave JS triggers for the automation editor (home-assistant#181129) Add ScorpionTrack last reported sensor (home-assistant#178755) Fix llama.cpp streaming capability reporting (home-assistant#179886) Report the Weheat cooling start conditions (home-assistant#181287) Fix swallowed exceptions in action handlers for Huawei LTE (home-assistant#181538) Fix swallowed exceptions in action handlers for ColorExtractor (home-assistant#181537) Add binary_sensor platform to NeoPool (home-assistant#180393) Bump vizaio to 0.6.2 (home-assistant#181562) Handle reauth_successful centrally (home-assistant#181154) Fix Vizio soundbars requiring authentication (home-assistant#181556) ...
Proposed change
Protect mutable
allowed_context_keysattribute inSelectorbased classesType 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: