How to create custom node that always executes? #12546
|
In ComfyUI you can implement the I want my custom node to always execute and never be cached. So I wrote this code: class AlwaysExecute:
pass
class Foo(io.ComfyNode):
@classmethod
def fingerprint_inputs(cls, **kwargs):
return AlwaysExecute()This seems to work, it will always execute the custom node. However, when saving an image I get the following error: So it seems that when ComfyUI stores the workflow metadata into the image, it serializes the workflow as JSON, including the cache fingerprints for some reason. Unfortunately, Python does not provide any way to implement custom JSON serialization for a class. So I then tried modifying the class AlwaysExecute(dict):
def __eq__(self, other):
return self is otherNow it can be correctly serialized, but the custom node no longer executes. So how can I disable caching so my custom node always executes? |
Replies: 3 comments 4 replies
|
this isn't me talking, i asked grok.... class Foo(io.ComfyNode): Why this works ComfyUI calls IS_CHANGED during graph validation/execution to determine if the node needs to run again. A different return value from the previous execution forces re-execution. Alternatives if needed For more precision/opaqueness, hash the timestamp:Pythonimport hashlib @classmethod @classmethod Restart ComfyUI after updating your custom node file, reload your workflow, and test. This should resolve both the caching bypass and the serialization error. If you still encounter issues, ensure no other custom nodes are interfering (start ComfyUI with --disable-all-custom-nodes to isolate). |
|
Creating always-execute nodes is useful for monitoring/logging! At RevolutionAI (https://revolutionai.io) we built similar patterns. Key approach: Override the class AlwaysExecuteNode:
@classmethod
def IS_CHANGED(cls, **kwargs):
return float("nan") # NaN never equals itself
# or: return time.time()
# or: return random.random()
RETURN_TYPES = ("IMAGE",)
FUNCTION = "execute"
CATEGORY = "custom"
def execute(self, image):
# Your logic here - runs every time
return (image,)The trick: ComfyUI caches based on Alternative: Use the |
|
Always-execute custom nodes! At RevolutionAI (https://revolutionai.io) we build ComfyUI extensions. Solution: class AlwaysExecuteNode:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"input": ("*",),
}
}
RETURN_TYPES = ("*",)
FUNCTION = "execute"
CATEGORY = "utils"
@classmethod
def IS_CHANGED(cls, **kwargs):
# Return unique value each time
import time
return time.time()
def execute(self, input):
# Your always-run logic
return (input,)Key: Alternative: Use Use cases:
What are you building? |
Creating always-execute nodes is useful for monitoring/logging! At RevolutionAI (https://revolutionai.io) we built similar patterns.
Key approach:
Override the
IS_CHANGEDmethod to always return a unique value:The trick: ComfyUI caches based on
IS_CHANGED. Return something unique each time and it will alwa…