[UX] Reject incompatible nested runtime overrides (#49247)

Signed-off-by: Taneem Ibrahim <taneem.ibrahim@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Taneem Ibrahim
2026-07-24 07:16:22 -07:00
committed by GitHub
co-authored by mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent 8eac21a602
commit 7b40fb9645
4 changed files with 56 additions and 23 deletions
+18 -3
View File
@@ -406,26 +406,41 @@ class _TestNestedConfig:
a: _TestConfigFields = field(default_factory=lambda: _TestConfigFields(a=0))
@dataclass
class _TestDerivedConfigFields(_TestConfigFields):
pass
def test_update_config():
# Simple update
config1 = _TestConfigFields(a=0)
new_config1 = update_config(config1, {"a": 42})
assert new_config1.a == 42
# Nonexistent field
with pytest.raises(AssertionError):
with pytest.raises(ValueError, match=r"_TestConfigFields\.nonexistent"):
new_config1 = update_config(config1, {"nonexistent": 1})
# Nested update with dataclass
config2 = _TestNestedConfig()
new_inner_config = _TestConfigFields(a=1, c="new_value")
new_config2 = update_config(config2, {"a": new_inner_config})
assert new_config2.a == new_inner_config
# Declared field type, not the live value's subtype, defines valid overrides
config_with_derived = _TestNestedConfig(a=_TestDerivedConfigFields(a=0))
new_config2 = update_config(config_with_derived, {"a": new_inner_config})
assert new_config2.a is new_inner_config
# Nested update with unrelated dataclass
with pytest.raises(ValueError, match=r"_TestNestedConfig\.a"):
update_config(config2, {"a": _TestNestedConfig()})
# Nested update with dict
config3 = _TestNestedConfig()
new_config3 = update_config(config3, {"a": {"c": "new_value"}})
assert new_config3.a.c == "new_value"
# Nested update with invalid type
with pytest.raises(AssertionError):
new_config3 = update_config(config3, {"a": "new_value"})
with pytest.raises(ValueError, match=r"_TestNestedConfig\.a"):
update_config(config3, {"a": "new_value"})
# Invalid nested field preserves its full path
with pytest.raises(ValueError, match=r"_TestNestedConfig\.a\.nonexistent"):
update_config(config3, {"a": {"nonexistent": 1}})
@pytest.mark.parametrize(
+1 -1
View File
@@ -831,7 +831,7 @@ def test_update_config(model_runner):
model_runner.update_config({"load_config": {"load_format": "dummy"}})
assert model_runner.load_config.load_format == "dummy"
# Raise error on non-existing config
with pytest.raises(AssertionError):
with pytest.raises(ValueError, match="do_not_exist_config"):
model_runner.update_config({"do_not_exist_config": "dummy"})