Skip to content

Commit d883a48

Browse files
kingpanther13claude
andcommitted
fix(flows): reject an explicit null step_values directive
The guard returned early on a falsy directive, so {'step_values': None} passed validation — and because the reserved key is excluded from ignored-key reporting, the walk then applied the caller's other fields and returned a clean success for a directive that did nothing. Key PRESENCE is the test, so an explicit None now falls through to the not-an-object rejection. Found by CodeRabbit review on #2256. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012d29UJTiH4Uy2Pm37SBPtr
1 parent 4ab5979 commit d883a48

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/ha_mcp/tools/config_entry_flow_form.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,9 +852,13 @@ def validate_step_values(config: dict[str, Any]) -> None:
852852
Accepted: a dict of ``step_id -> entry``, where an entry is a dict of field
853853
values, or a LIST of such dicts consumed one per encounter of that step.
854854
"""
855-
directive = config.get(_PER_STEP_VALUES_KEY)
856-
if directive is None:
855+
# Key PRESENCE is the test, not truthiness: an explicit ``None`` is a
856+
# caller who meant to pass a directive and got the shape wrong, and the
857+
# reserved key hides it from ignored-key reporting, so returning early on
858+
# it would let the walk apply the rest and report a clean success.
859+
if _PER_STEP_VALUES_KEY not in config:
857860
return
861+
directive = config[_PER_STEP_VALUES_KEY]
858862

859863
example = "{'<step_id>': {'<field>': <value>}}"
860864
if not isinstance(directive, dict):

tests/src/unit/test_flow_options_preserve.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,8 +1235,8 @@ class TestStepValuesValidation:
12351235

12361236
@pytest.mark.parametrize(
12371237
"directive",
1238-
["oops", 42, ["init"]],
1239-
ids=["string", "number", "list"],
1238+
["oops", 42, ["init"], None],
1239+
ids=["string", "number", "list", "explicit-null"],
12401240
)
12411241
def test_a_non_object_directive_is_rejected(self, directive: Any) -> None:
12421242
with pytest.raises(ToolError) as exc_info:

0 commit comments

Comments
 (0)