Another stupid issue with merge?

I have created quite nice workflow but then observed that something is wrong…

To make it more visible I have simplified this to simple problem with Merge node

4 blocks

  • start
  • IF (always false)
  • Code (always return something
  • Merge Code and IF
    Logically Merge shroud not return anything.
    But when you look at the green lines - it triggers next nodes

Is there something I don’t understand and don’t know how it works or is it just not working?
I’ve read the threads on the forums but they all refer to old versions of Merge.
Latest online n8n version.

PS: YES I know that I can create merge with Chose Branch option, but this will work only for simple cases. If I will have node CODE instead of IF (and sometime return valid data and sometime not) then Chose Branch is not enough.

Documentation of Merge states in first line:
“Use the Merge node to combine data from multiple streams, once data of all streams is available.”

![image|690x414](upload://Ou5OmLOJWTLXlBOM1tdUxIBxik.png)
{
  "nodes": [
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        20,
        -80
      ],
      "id": "7e78345e-4582-45c3-b137-0d5c05fe2142",
      "name": "When clicking ‘Test workflow’"
    },
    {
      "parameters": {
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfor (const item of $input.all()) {\n  item.json.myNewField = 1;\n}\n\nreturn $input.all();"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        200,
        20
      ],
      "id": "da9af0ec-0b02-49e6-85ef-ac7a94ec1cae",
      "name": "Code"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "1b426ded-ec07-4e36-8e29-085d43e2545f",
              "leftValue": "1",
              "rightValue": "0",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        200,
        -100
      ],
      "id": "3bc50cfe-cc28-47b2-ad2e-f9c2394b24d5",
      "name": "If"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.1,
      "position": [
        480,
        -80
      ],
      "id": "09e4dbc4-10cd-45f1-a97d-3988e5ce2334",
      "name": "Merge"
    }
  ],
  "connections": {
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          },
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "meta": {
    "instanceId": "a1b4c568c99e4f8f7799fc00ae4d7e0c29a1e8ebd3776f72563c59b47eb3d28b"
  }
}
1 Like

Just curious:

If something after an IF node is false,

what do you expect to happen in the rest of the workflow?

Even if the Merge node isn’t executed, the workflow will stop at the Merge, right?

My first thought will be output the false in the input1 and doing some check or process after the Merge result and continue.

Thanks for Answer.
The problem however is not with IF. The problem is with MERGE - as you see on my picture - AFTER Merge there is a green line = which means it went through merge, even though there were no input from IF. So the problem is that Merge pass the data here.

You’re using it wrong. Merge Apend is meant for appending arrays as far as I understand it. However, when you use Merge to Combine on Position, it will not continue until ALL input arrive at the merge:

Sometime you do not need to combine.
What is the sense to have 2 sources while you are not waiting for both of them?
One of them is always faster.

Im not sure I understand your complaint? The solution I gave above stops the workflow if both inputs have not arrived.

What exactly is your use case or logic required? Can you give a real world example

While we have different number of elements in Merge (like 20 on one connection and 5 on another connection) You do not always want to Combine than just like that, or you don’t want always want to use Position for that. In that sense while Merge is not waiting for both inputs then I need even more blocks to achieve what I want with using Combine.

So I am not saying that I am not able to achieve what I want. It is possible!

But while I need to use 50%+ of nodes to technically manage thee data that I am passing through. This is super inefficient.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.