-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Accept a YAML list in extra_model_paths.yaml instead of crashing #15841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ntdat812
wants to merge
2
commits into
Comfy-Org:master
Choose a base branch
from
ntdat812:fix/extra-model-paths-yaml-shapes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+170
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| """A YAML list of paths in extra_model_paths.yaml aborted startup. | ||
|
|
||
| `load_extra_path_config()` called `.split("\\n")` on every value, so the shape | ||
| people naturally write — | ||
|
|
||
| comfyui: | ||
| base_path: /models | ||
| checkpoints: | ||
| - ckpt_a | ||
| - ckpt_b | ||
|
|
||
| — raised `AttributeError: 'list' object has no attribute 'split'`, a traceback | ||
| naming neither the file nor the key. Measured on master before the change: | ||
|
|
||
| list of paths -> AttributeError: 'list' object has no attribute 'split' | ||
| numeric value -> AttributeError: 'int' object has no attribute 'split' | ||
| nested mapping -> AttributeError: 'dict' object has no attribute 'split' | ||
| section is a string -> TypeError: string indices must be integers | ||
| newline string -> ok (the documented form, unaffected) | ||
|
|
||
| A malformed entry now warns and is skipped, so one bad key no longer takes the | ||
| whole config — and the rest of the search paths still load. | ||
| """ | ||
|
|
||
| import itertools | ||
| import os | ||
|
|
||
| import pytest | ||
| from unittest.mock import patch | ||
|
|
||
| import folder_paths | ||
| from utils.extra_config import load_extra_path_config | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def load_yaml(tmp_path): | ||
| """Write a config, load it, and return the paths that were registered.""" | ||
| counter = itertools.count() | ||
|
|
||
| def _load(text: str) -> list[tuple]: | ||
| # `tmp_path` is cleaned up by pytest; a fresh name per call keeps two | ||
| # loads in the same test from overwriting each other. | ||
| path = tmp_path / f"extra_model_paths_{next(counter)}.yaml" | ||
| path.write_text(text, encoding="utf-8") | ||
| path = str(path) | ||
|
|
||
| added: list[tuple] = [] | ||
| with patch.object( | ||
| folder_paths, "add_model_folder_path", lambda *args, **kwargs: added.append(args) | ||
| ): | ||
| load_extra_path_config(path) | ||
| return added | ||
|
|
||
| return _load | ||
|
|
||
|
|
||
| def _basenames(added: list[tuple]) -> list[str]: | ||
| return [os.path.basename(entry[1]) for entry in added] | ||
|
|
||
|
|
||
| def test_list_of_paths_is_accepted(load_yaml): | ||
| added = load_yaml( | ||
| "comfyui:\n" | ||
| " base_path: /models\n" | ||
| " checkpoints:\n" | ||
| " - ckpt_a\n" | ||
| " - ckpt_b\n" | ||
| ) | ||
|
|
||
| assert _basenames(added) == ["ckpt_a", "ckpt_b"] | ||
| assert [entry[0] for entry in added] == ["checkpoints", "checkpoints"] | ||
|
|
||
|
|
||
| def test_newline_string_is_unchanged(load_yaml): | ||
| """The documented form must keep behaving exactly as before.""" | ||
| added = load_yaml( | ||
| "comfyui:\n" | ||
| " base_path: /models\n" | ||
| " checkpoints: |\n" | ||
| " ckpt_a\n" | ||
| " ckpt_b\n" | ||
| ) | ||
|
|
||
| assert _basenames(added) == ["ckpt_a", "ckpt_b"] | ||
|
|
||
|
|
||
| def test_list_and_string_agree(load_yaml): | ||
| as_list = load_yaml("comfyui:\n base_path: /models\n checkpoints:\n - a\n - b\n") | ||
| as_string = load_yaml("comfyui:\n base_path: /models\n checkpoints: |\n a\n b\n") | ||
|
|
||
| assert as_list == as_string | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "bad_value", | ||
| [ | ||
| " checkpoints: 42\n", | ||
| " checkpoints: true\n", | ||
| " checkpoints:\n a: b\n", | ||
| ], | ||
| ) | ||
| def test_a_malformed_value_is_skipped_without_losing_the_rest(load_yaml, bad_value): | ||
| added = load_yaml("comfyui:\n base_path: /models\n" + bad_value + " loras: keep_me\n") | ||
|
|
||
| assert _basenames(added) == ["keep_me"] | ||
|
|
||
|
|
||
| def test_a_malformed_entry_inside_a_list_is_skipped(load_yaml): | ||
| added = load_yaml( | ||
| "comfyui:\n base_path: /models\n checkpoints:\n - ok_a\n - 7\n" | ||
| ) | ||
|
|
||
| assert _basenames(added) == ["ok_a"] | ||
|
|
||
|
|
||
| def test_a_section_that_is_not_a_mapping_is_skipped(load_yaml): | ||
| added = load_yaml("comfyui: /models\nother:\n base_path: /m2\n loras: keep_me\n") | ||
|
|
||
| assert _basenames(added) == ["keep_me"] | ||
|
|
||
|
|
||
| def test_an_empty_section_is_still_tolerated(load_yaml): | ||
| added = load_yaml("comfyui:\nother:\n base_path: /m2\n loras: keep_me\n") | ||
|
|
||
| assert _basenames(added) == ["keep_me"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.