From 47f2bd7ca4550310482f9cc3f168364d7441ac2b Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 30 Oct 2026 17:50:35 +0000 Subject: [PATCH] Settings: a value that is wrong for a setting hidden by another's choice no longer stops the run; its default stands Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01Tw9fjWzZx5QzcqkheSuhsy --- core/schema.py | 8 ++++++++ core/tests/test_schema.py | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/core/schema.py b/core/schema.py index 2fd8f952..67582de6 100644 --- a/core/schema.py +++ b/core/schema.py @@ -273,6 +273,8 @@ def check_values(spec, values: Any, keep_bad: bool = False) -> Tuple[Dict[str, A f"{spec.id}: saved setting {key!r} ignored: this module has no such setting") continue problem = _value_problem(declared, key, value, spec.id) + if problem and not _applies(declared, {**spec.defaults(), **values}): + continue # a setting that is hidden by another one's choice cannot act, so it cannot stop the run: its default stands if problem: problems.append(problem) if not keep_bad: @@ -281,6 +283,12 @@ def check_values(spec, values: Any, keep_bad: bool = False) -> Tuple[Dict[str, A return clean, problems +def _applies(declared: dict, merged: dict) -> bool: + """Whether a setting's `when` holds with these values (a setting with none always applies).""" + return all(merged.get(other) in (expected if isinstance(expected, list) else [expected]) + for other, expected in (declared.get("when") or {}).items()) + + def _value_problem(declared: dict, key: str, value: Any, module_id: str): kind = declared["type"] where = f"{module_id}.{key}" diff --git a/core/tests/test_schema.py b/core/tests/test_schema.py index d9247d06..f3867f19 100644 --- a/core/tests/test_schema.py +++ b/core/tests/test_schema.py @@ -331,3 +331,15 @@ def test_roles_a_module_acts_through_reach_the_manifest(): assert validate(announce(roles=["assets.source_image"])).to_manifest()["roles"] == ["assets.source_image"] with pytest.raises(SchemaError, match="roles"): validate(announce(roles="assets.source_image")) + + +def test_a_hidden_setting_with_a_bad_value_does_not_stop_the_run(): + from types import SimpleNamespace + from core import schema + settings = {"method": {"type": "enum", "default": "plain", "options": [{"value": "plain"}, {"value": "file"}]}, + "file": {"type": "enum", "default": "a.pth", "options": [{"value": "a.pth"}], "when": {"method": "file"}}} + spec = SimpleNamespace(id="m", settings=settings, defaults=lambda: {k: v["default"] for k, v in settings.items()}) + clean, problems = schema.check_values(spec, {"method": "plain", "file": "other.safetensors"}) + assert problems == [] and clean["file"] == "a.pth" + clean, problems = schema.check_values(spec, {"method": "file", "file": "other.safetensors"}) + assert problems and "m.file must be one of" in problems[0]