Comfy-Org / Comfy-Org/ComfyUI

[Feature request]: None and Empty Lists node results could interrupt only the branch of the tree below that node, instead of raising an error

Open
#2,913 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
133k
Forks
15.7k
Avg merge
1d 10h
Merged PRs (30d)
153

Description

For the context, here is a simple workflow:
![image](https://github.com/comfyanonymous/ComfyUI/assets/1372055/97f87bad-11cc-4f95-ad28-f845b66b8419)
It loads an image, detect and crop the faces, then filter the faces asking only for female faces here, and finally show a preview of the crop.
Obviously, in the loaded image, there is only a handsome man, so it doesn't detect female faces, and `GenderFaceFilter` returns an empty list. The empty list is then processed by `FaceDetails` which outputs a tuple of three empty lists: `([], [], [])`. Finally, the first output is sent to `PreviewImage`, and we have this at the beginning of `SaveImage` node:
```python
def save_images(self, images, filename_prefix="ComfyUI", prompt=None, extra_pnginfo=None):
filename_prefix += self.prefix_append
full_output_folder, filename, counter, subfolder, filename_prefix = folder_paths.get_save_image_path(filename_prefix, self.output_dir, images[0].shape[1], images[0].shape[0])
results = list()
for (batch_number, image) in enumerate(images):
```
Obviously, `SaveImage` expects a list of images with at least one image. An empty list will cause an error.

This is not the only place where there is this kind of behavior, so fixing this node in particular won't really help. I think there should be a mechanism within `execution.py` that stops further execution of a node (and all the below branch directly attached to this node) whenever a node fails when the execution already started. Why?

- If the execution already started, it means that the workflow passed the validation check, and thus is a valid workflow.
- Not handling empty lists and None as a possible input makes developing new custom nodes very weird in some cases.
In this particular example above, how someone is supposed to develop nodes to obtain this kind of workflow?
-- If no object (female face here) is detected, what should it return? A black image and a warp matrix that will blit the black image far outside the bounds of the original picture? But that means any possible subsequent processing (like KSampling, etc) on this black image will occur (and waste time/computational ressource) when it should just really have not happened at all.
-- Or should we develop special nodes to handle these cases, like what is happening with Impact-Pack and his SEGSDetailer node? Basically create a special KSampler that can handle empty lists? But then should we also develop similar special nodes for SaveImage, Blur, Detectors, and basically every other node that could get an image (or whatever input really)?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.