{"record":{"id":"ec743dbdc9c0b585","repo":"Comfy-Org/ComfyUI","slug":"injectionshook-is-not-supported-yet-in-comfyui","errorCode":null,"errorMessage":"InjectionsHook is not supported yet in ComfyUI.","messagePattern":"InjectionsHook is not supported yet in ComfyUI\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"comfy/hooks.py","lineNumber":285,"sourceCode":"WrapperHook = TransformerOptionsHook\n'''Only here for backwards compatibility, WrapperHook is identical to TransformerOptionsHook.'''\n\nclass InjectionsHook(Hook):\n    def __init__(self, key: str=None, injections: list[PatcherInjection]=None,\n                 hook_scope=EnumHookScope.AllConditioning):\n        super().__init__(hook_type=EnumHookType.Injections)\n        self.key = key\n        self.injections = injections\n        self.hook_scope = hook_scope\n\n    def clone(self):\n        c: InjectionsHook = super().clone()\n        c.key = self.key\n        c.injections = self.injections.copy() if self.injections else self.injections\n        return c\n\n    def add_hook_patches(self, model: ModelPatcher, model_options: dict, target_dict: dict[str], registered: HookGroup):\n        raise NotImplementedError(\"InjectionsHook is not supported yet in ComfyUI.\")\n\nclass HookGroup:\n    '''\n    Stores groups of hooks, and allows them to be queried by type.\n\n    To prevent breaking their functionality, never modify the underlying self.hooks or self._hook_dict vars directly;\n    always use the provided functions on HookGroup.\n    '''\n    def __init__(self):\n        self.hooks: list[Hook] = []\n        self._hook_dict: dict[EnumHookType, list[Hook]] = {}\n\n    def __len__(self):\n        return len(self.hooks)\n\n    def add(self, hook: Hook):\n        if hook not in self.hooks:\n            self.hooks.append(hook)","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/hooks.py#L267-L303","documentation":"Raised by InjectionsHook.add_hook_patches. Like ObjectPatchHook, the InjectionsHook type is declared (and round-trips through hook serialization) but applying its injections was never implemented in ComfyUI. Any attempt to register it with a ModelPatcher raises NotImplementedError before any model forward runs.","triggerScenarios":"Creating an InjectionsHook(key=..., injections=[...]) and letting the hook application machinery call add_hook_patches; deserializing a saved HookGroup that contains an Injections hook; extensions that build injection hooks expecting fork-level support.","commonSituations":"Workflows authored on forks (e.g. ones with weight-injection features) loaded in stock ComfyUI; custom nodes enumerating EnumHookType.Injections and assuming every type is live.","solutions":["Implement the injection as a regular model forward wrapper via ModelPatcher.set_model_... APIs or patches dict instead of hooks","Remove the Injections hooks from the workflow/conditioning before running in stock ComfyUI","Gate your extension code on availability: skip Injections hooks when add_hook_patches is the stock unimplemented one"],"exampleFix":"# before\nhook = hooks.InjectionsHook(key='block_3', injections=[inj])\n# after (apply injection at patch time)\nmodel_patcher.set_model_input_block_patch(inj_fn, block_id=3)","handlingStrategy":"type-guard","validationCode":"from comfy.hooks import InjectionsHook\nassert not isinstance(hook, InjectionsHook), 'InjectionsHook application is not implemented in ComfyUI'","typeGuard":"def hook_is_applicable(hook) -> bool:\n    return not isinstance(hook, comfy.hooks.InjectionsHook)","tryCatchPattern":"try:\n    hook.add_hook_patches(model_patcher, model_options, target_dict, group)\nexcept NotImplementedError:\n    apply_injection_via_patch_dict(model_patcher, hook.injections)","preventionTips":["Implement injections as model patches or wrappers, not hooks","Filter serialized hook groups by supported EnumHookType before applying"],"tags":["hooks","not-implemented","injections","compatibility"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}