[Bug] Merge Node Returns Incorrect Data

Issue Summary

When using a Merge node within a workflow that includes a Loop Over Items and an If node, the Merge node does not return the expected filtered data. Specifically, it includes items that should have been filtered out based on the conditions in the If node.

Workflow

Workflow Explanation

In this workflow:

  1. Code node generates an array of items, each with a "name", "value", and "ok" property.
  2. The Loop Over Items node iterates over each item.
  3. The If node checks if "ok" is true and only allows items that match this condition to continue.
  4. The Merge node is expected to aggregate only the items where "ok" is true from the If node.

Expected Output vs. Actual Output

  • Expected Output: Only items with "ok": true are included.
  • Actual Output: The output unexpectedly includes items with "ok": false, meaning the Merge node is not consistently excluding items based on the If condition.

Environment Details

  • n8n version: 1.58.1
  • Database: SQLite (default)
  • Execution Process: Own (default, main)
  • Running n8n on: n8n Cloud

Could anyone help troubleshoot why the Merge node isn’t applying the If condition correctly within the loop?

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

I think this is a bug!

hello @tranlight

That’s because you can’t go for the next iteration when the IF node goes to the false branch. Both Merge branches should be involved in any way. Consider changing the logic (e.g. move the Loop functionality into the sub workflow or do not use Loop)