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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tw9fjWzZx5QzcqkheSuhsy
This commit is contained in:
@@ -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}"
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user