ComfyUI Node

discard

The set node that never throws a fit

By StableLlama·Created about a year ago·Updated 4 days ago· 48
discard
  • set
  • item
  • SET

discard removes an item from a set if it's there, and if it isn't - nothing happens. No error, no fuss, no drama. It's the laid-back sibling of this pack's remove node, which raises the question of why both exist.

The answer is what you plan to do with failure. remove gives you a success boolean so your workflow can branch on whether the item was actually there. discard is for when you just want the item gone and genuinely don't care whether it existed. Think of it like trimming a tag list: you want "watermark" out of your set, and if it was never in there, so much the better. There's no point crashing a workflow over a tag that's already absent.

It's one of those "small but it composes" nodes. You'll typically chain it after a union or difference when building up a curated set, or use it to scrub a set before converting it to a data list for per-item processing.

How it works

The mechanism is Python's set.discard(): the node copies the input set, calls discard with the item, and returns the copy. Because it copies rather than mutating, the original set is untouched - you can still use it elsewhere in the graph.

The "no error if absent" behavior is the entire personality of this node. Python's set.remove() raises a KeyError on a missing item; set.discard() silently returns. This node implements the discard flavor, so an absent item just means you get the set back unchanged.

Inputs and output

  • set (SET) - the set you want to remove from.
  • item (ANY) - the item to discard. Anything hashable works; the type just has to match what's in the set ("3" and 3 are different items).
  • SET (output) - the set with the item removed, or unchanged if it wasn't present.

Installing

It's in Basic data handling by StableLlama. Easiest via ComfyUI Manager - search "Basic data handling" and install, then restart. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling

Restart ComfyUI after cloning. No dependencies, no model downloads - this pack is pure Python utilities, so the whole thing installs in seconds.

Common issues

The only real confusion is picking discard when you needed the feedback. If you want to know whether the removal happened - to branch a workflow on it - use remove instead, which outputs a success boolean. And remember the item has to match exactly: sets compare values, not friendly approximations. If your item is a string and the set holds integers, you'll silently discard nothing.

CategoryBasic/SET

Inputs (2)

NameTypeDefaultDescription
setSET
item*

Outputs (1)

NameTypeDescription
SETSET