From f334f2db3d3eca1f86867862a32ea87aa07cb91c Mon Sep 17 00:00:00 2001 From: cest-la-v <22951622+cest-la-v@users.noreply.github.com> Date: Sun, 26 Apr 2026 20:44:41 +0800 Subject: [PATCH] fix: nested models: block inherits outer block_base and block_is_default When models: has no base_path or is_default of its own, fall back to the enclosing block's values instead of None/False. This ensures relative category paths resolve against the outer base_path as users would expect. --- tests-unit/utils/extra_config_test.py | 27 +++++++++++++++++++++++++++ utils/extra_config.py | 4 ++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/tests-unit/utils/extra_config_test.py b/tests-unit/utils/extra_config_test.py index 1112320d9..69007d753 100644 --- a/tests-unit/utils/extra_config_test.py +++ b/tests-unit/utils/extra_config_test.py @@ -591,3 +591,30 @@ def test_explicit_custom_nodes_key(mock_yaml_load, clear_folder_paths, tmp_path) assert os.path.normpath(str(tmp_path / "my_nodes")) in \ folder_paths.folder_names_and_paths["custom_nodes"][0] + +@patch("yaml.safe_load") +def test_nested_models_inherits_block_base(mock_yaml_load, clear_folder_paths, tmp_path): + """models: block without its own base_path inherits the outer block's base_path.""" + config_data = { + "comfyui": { + "base_path": str(tmp_path), + "is_default": True, + "models": { + "checkpoints": "models/checkpoints/", + }, + } + } + mock_yaml_load.return_value = config_data + folder_paths.folder_names_and_paths["checkpoints"] = ([], set()) + + yaml_path = str(tmp_path / "extra_paths.yaml") + with open(yaml_path, "w") as f: + f.write("") + + load_extra_path_config(yaml_path) + + expected = os.path.normpath(str(tmp_path / "models" / "checkpoints")) + paths = folder_paths.folder_names_and_paths["checkpoints"][0] + assert expected in paths + # is_default inherited: path should be at index 0 + assert paths[0] == expected diff --git a/utils/extra_config.py b/utils/extra_config.py index 8ba1bdc38..d14a40a35 100644 --- a/utils/extra_config.py +++ b/utils/extra_config.py @@ -81,10 +81,10 @@ def load_extra_path_config(yaml_path: str, allow_system_dirs: bool = False) -> N # New nested style: models: { base_path, is_default, } has_models_block = True models_conf = dict(value) - models_base = None + models_base = block_base if "base_path" in models_conf: models_base = _resolve_base(models_conf.pop("base_path"), block_base, yaml_dir) - models_is_default = bool(models_conf.pop("is_default", False)) + models_is_default = bool(models_conf.pop("is_default", block_is_default)) explicit: set[str] = set(models_conf.keys()) for cat, raw in models_conf.items(): _add_model_paths(cat, raw, models_base, yaml_dir, models_is_default)