diff --git a/core/graph.py b/core/graph.py index 35afea60..ea77ed08 100644 --- a/core/graph.py +++ b/core/graph.py @@ -651,9 +651,10 @@ def _pass_through(node: str, schemas: Schemas) -> Optional[Tuple[str, str, int]] """(kind, its one input, its output index) for a node that takes and gives one kind (MODEL in, MODEL out), or None: any other node's wiring is the person's call.""" produced = schemas.outputs(node) + must = schemas.required(node) # a LoRA loader's optional CLIP does not stop it being a MODEL patch; a schema naming none counts every input kinds = [] for kind in dict.fromkeys(k for k in produced if k not in comfy_types.PRIMITIVE and k != "*"): - ins = [n for n, wants in schemas.inputs(node).items() if wants == kind] + ins = [n for n, wants in schemas.inputs(node).items() if wants == kind and (not must or n in must)] if len(ins) == 1: kinds.append((kind, ins[0], produced.index(kind))) return kinds[0] if len(kinds) == 1 else None diff --git a/core/tests/test_graph.py b/core/tests/test_graph.py index 01cd76cf..a6bf98aa 100644 --- a/core/tests/test_graph.py +++ b/core/tests/test_graph.py @@ -660,3 +660,20 @@ def test_a_dynamic_dropdowns_fields_are_inputs_and_needed_only_for_their_choice( "selection.keep_percent": ("selection", ["sla", "vsa"])}}}.get) assert schemas.required("Sparse", {"selection": "vsa"}) == ["model", "selection", "selection.keep_percent"] assert schemas.required("Sparse", {"selection": "sol-attn"}) == ["model", "selection", "selection.tau"] + + +def test_a_lora_loader_added_after_the_first_goes_into_the_model_chain(): + """Its CLIP in/out is optional, so it is still a MODEL patch: left loose it never ran, and the + sampler read only the first LoRA.""" + nodes = {"Lora": {"inputs": {"model": "MODEL", "lora_name": "COMBO", "clip": "CLIP"}, "outputs": ["MODEL", "CLIP", "STRING"], "required": ["model", "lora_name"]}, + "Loader": {"inputs": {}, "outputs": ["MODEL"]}, "Sampler": {"inputs": {"model": "MODEL"}, "outputs": ["LATENT"], "required": ["model"]}} + schemas = graph.Schemas(nodes.get) + slots = [{"id": "model", "node": "Loader", "inputs": {}}, {"id": "lora", "node": "Lora", "inputs": {"model": ["model", 0], "lora_name": "a"}}, + {"id": "sample", "node": "Sampler", "inputs": {"model": ["lora", 0]}}] + for _ in range(3): + slots, _p = graph.add(slots, "Lora", None, schemas) + slots, note = graph.splice(slots, slots[-1]["id"], schemas) + assert note is None + by = graph.slots_by_id(slots) + assert [by[i]["inputs"]["model"][0] for i in ("lora_2", "lora_3", "lora_4")] == ["lora", "lora_2", "lora_3"] + assert by["sample"]["inputs"]["model"] == ["lora_4", 0]