fix: move LoRA cache off the node class for ComfyUI locked classes
Newer ComfyUI builds lock registered v3 node classes after registration (comfy_api internal __setattr__ guard), so _apply_lora writing cls._loaded_lora raised: Cannot modify class attribute '_loaded_lora' on locked class 'MoxieMultimediaLoaderClone'. The (path, sd, metadata) cache now lives at module level, which the locking mechanism does not touch. Test monkeypatch updated to match.
This commit is contained in:
parent
645897130b
commit
d3ce6866a4
@ -53,6 +53,13 @@ def _resolve(subdir, name):
|
||||
return path
|
||||
|
||||
|
||||
# (path, sd, metadata) cache for the last parsed LoRA, mirroring the native
|
||||
# LoraLoader. Kept at module level on purpose: newer ComfyUI builds lock node
|
||||
# classes after registration, so writing class attributes on the node class
|
||||
# itself raises "Cannot modify class attribute ... on locked class".
|
||||
_loaded_lora = None
|
||||
|
||||
|
||||
def _h3_clip_type():
|
||||
"""MiniMax H3 CLIP recipe. The Moxie model set is H3-only, so the text
|
||||
encoder type is intentionally NOT a user-facing choice."""
|
||||
@ -74,8 +81,6 @@ class MoxieMultimediaLoader(io.ComfyNode):
|
||||
CLIPType.MINIMAX and outputs are exactly (model, clip, video_vae, audio_vae)
|
||||
with the attention backend and LoRA already applied to the model."""
|
||||
|
||||
_loaded_lora = None # (path, sd, metadata) cache, mirrors native LoraLoader
|
||||
|
||||
@classmethod
|
||||
def define_schema(cls) -> io.Schema:
|
||||
# The published pack ships its models inside the repo, so default to
|
||||
@ -188,6 +193,7 @@ class MoxieMultimediaLoader(io.ComfyNode):
|
||||
|
||||
@classmethod
|
||||
def _apply_lora(cls, model, clip, lora_name, strength_model, strength_clip):
|
||||
global _loaded_lora
|
||||
if (
|
||||
lora_name is None
|
||||
or lora_name == "none"
|
||||
@ -199,16 +205,16 @@ class MoxieMultimediaLoader(io.ComfyNode):
|
||||
lora_path = _resolve("loras", lora_name)
|
||||
lora = None
|
||||
lora_metadata = None
|
||||
if cls._loaded_lora is not None:
|
||||
if cls._loaded_lora[0] == lora_path:
|
||||
lora = cls._loaded_lora[1]
|
||||
lora_metadata = cls._loaded_lora[2] if len(cls._loaded_lora) > 2 else None
|
||||
if _loaded_lora is not None:
|
||||
if _loaded_lora[0] == lora_path:
|
||||
lora = _loaded_lora[1]
|
||||
lora_metadata = _loaded_lora[2] if len(_loaded_lora) > 2 else None
|
||||
else:
|
||||
cls._loaded_lora = None
|
||||
_loaded_lora = None
|
||||
|
||||
if lora is None:
|
||||
lora, lora_metadata = comfy.utils.load_torch_file(lora_path, safe_load=True, return_metadata=True)
|
||||
cls._loaded_lora = (lora_path, lora, lora_metadata)
|
||||
_loaded_lora = (lora_path, lora, lora_metadata)
|
||||
|
||||
model_lora, clip_lora = comfy.sd.load_lora_for_models(
|
||||
model, clip, lora, strength_model, strength_clip, lora_metadata=lora_metadata
|
||||
|
||||
@ -372,7 +372,9 @@ def test_loader_execute_applies_attention_then_lora(moxie, monkeypatch, tmp_path
|
||||
}[name]
|
||||
(models / subdir / name).write_bytes(b"stub")
|
||||
monkeypatch.setattr(moxie.loader, "MODELS_DIR", models)
|
||||
monkeypatch.setattr(moxie.loader.MoxieMultimediaLoader, "_loaded_lora", None)
|
||||
# LoRA cache lives at module level: node classes are locked by newer
|
||||
# ComfyUI builds and class attributes can no longer be written at runtime.
|
||||
monkeypatch.setattr(moxie.loader, "_loaded_lora", None)
|
||||
state.calls.clear()
|
||||
|
||||
result = moxie.loader.MoxieMultimediaLoader.execute(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user