ComfyUI Node

merge

Merge up to four dicts, and the later one always wins

By StableLlama·Created about a year ago·Updated 4 days ago· 48
merge
  • dict1
  • dict2
  • dict3
  • dict4
  • DICT

"merge" combines up to four dictionaries into one. It's the combiner that makes the whole "build a dict here, build a dict there" pattern work - you assemble settings in pieces, then merge them into a single bundle before it travels downstream. It's also where a lot of dict bugs are born, because the merge order determines which value wins, and that's exactly the part people forget.

How it works

  • dict1 (DICT, required) - the base dictionary.
  • dict2, dict3, dict4 (DICT, optional) - the dictionaries layered on top.
  • Output: DICT - the merged result.

The rule is simple and absolute: on duplicate keys, the later dict wins. dict2 overrides dict1, dict4 overrides everything before it. In Python terms it's successive update() calls - left to right, rightmost wins. The merge is non-destructive; your input dicts are untouched, and you get a fresh combined dict.

The trap: it's order, not priority

This is the classic mistake, and it's worth stating slowly: later inputs win, and "later" is defined by which input port you connect. If you want defaults overridden by overrides, the defaults go in dict1 and the overrides go in dict2 - not the other way around. Wire it backwards and your "override" silently does nothing because the default value clobbers it.

A common shape: one dict built from user-facing settings, one built from hardcoded defaults, merged with settings in a later slot. Before you merge, decide which dict has authority and put it last.

When to use it

  • Layering a base config with per-branch overrides.
  • Combining metadata dicts from different sources into one bundle for a save node.
  • Merging the results of two create DICT nodes so you don't have to rebuild one giant dict by hand.

If you have more than four dicts, merge in stages - merge four, then merge the result with the next batch. If you need to exclude keys after merging, chain exclude keys on the output.

Install

Ships in Basic data handling - pure Python, zero dependencies, no model downloads. ComfyUI Manager → search "Basic data handling", or:

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

then restart ComfyUI. Indispensable for real dict workflows - just remember who's last.

CategoryBasic/DICT

Inputs (4)

NameTypeDefaultDescription
dict1DICT
dict2optDICT
dict3optDICT
dict4optDICT

Outputs (1)

NameTypeDescription
DICTDICT