When using a Merge node (in "append" mode, for example), attempting to reference an upstream node's data using the $('NodeName').item expression fails for items that originated from the Merge node's second input (or subsequent inputs). The expression works correctly for items that originated from the Merge node's first input.
This behavior is a regression, as it was working correctly in n8n version 1.82.2.
The error typically shown is "ERROR: Can't determine which item to use" or a similar paired item resolution failure.
{
"name": "Bug Test Workflow",
"nodes": [
{
"parameters": {
"numberInputs": 3
},
"type": "n8n-nodes-base.merge",
"typeVersion": 3.1,
"position": [
460,
200
],
"id": "92aad872-f96b-4785-a858-cf6ea48ef34c",
"name": "Merge",
"alwaysOutputData": true
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "63830a30-a4cc-4a66-9d01-8f0a058d4d43",
"name": "variable_1",
"value": "1234",
"type": "string"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
160,
0
],
"id": "54eaa8ed-b3e8-4c59-af23-9c74d0f15f95",
"name": "Set variable_1"
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "63830a30-a4cc-4a66-9d01-8f0a058d4d43",
"name": "variable_2",
"value": "2345",
"type": "string"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
160,
200
],
"id": "d3ecaea8-e30c-4911-9adf-78e12df5a7ac",
"name": "Set variable_2"
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "63830a30-a4cc-4a66-9d01-8f0a058d4d43",
"name": "variable_3",
"value": "3456",
"type": "string"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
160,
400
],
"id": "2e65f7a3-d1f8-44b4-9199-671ba502dd2e",
"name": "Set variable_3"
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "ed13172d-9bae-4b21-b168-577eee217e24",
"name": "final_variable_1",
"value": "={{ $('Set variable_1').item.json.variable_1 }}",
"type": "string"
},
{
"id": "7a92607d-d2f1-4b38-855f-4ec19b70f414",
"name": "final_variable_2",
"value": "={{ $('Set variable_2').item.json.variable_2 }}",
"type": "string"
},
{
"id": "89862e7d-0c44-4d6a-897e-a249c06f6346",
"name": "final_variable_3",
"value": "={{ $('Set variable_3').item.json.variable_3 }}",
"type": "string"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
680,
200
],
"id": "898d35e4-42a7-4fad-8a01-3f0d6d966cab",
"name": "Output"
},
{
"parameters": {},
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
-140,
200
],
"id": "12501aa5-502f-4960-a44a-833d017a6eb7",
"name": "Manual Trigger"
}
],
"pinData": {},
"connections": {
"Merge": {
"main": [
[
{
"node": "Output",
"type": "main",
"index": 0
}
]
]
},
"Set variable_1": {
"main": [
[
{
"node": "Merge",
"type": "main",
"index": 0
}
]
]
},
"Set variable_2": {
"main": [
[
{
"node": "Merge",
"type": "main",
"index": 1
}
]
]
},
"Set variable_3": {
"main": [
[
{
"node": "Merge",
"type": "main",
"index": 2
}
]
]
},
"Manual Trigger": {
"main": [
[
{
"node": "Set variable_2",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "a3cd04e1-304b-4752-8989-d299c622495c",
"meta": {
"instanceId": "b7c05a8986e66772aa7af4004a000d6c3b16ca93d88d75938718485e254b5a15"
},
"id": "QNCbSmpQ2GNK0w3R",
"tags": []
}
Bug Description
When using a Merge node (in "append" mode, for example), attempting to reference an upstream node's data using the
$('NodeName').itemexpression fails for items that originated from the Merge node's second input (or subsequent inputs). The expression works correctly for items that originated from the Merge node's first input.This behavior is a regression, as it was working correctly in n8n version 1.82.2.
The error typically shown is "ERROR: Can't determine which item to use" or a similar paired item resolution failure.
To Reproduce
To Reproduce:
Set variable_1,Set variable_2,Set variable_3).Set variable_1sets a field, e.g.,variable_1to1234.Set variable_2sets a field, e.g.,variable_2to2345.Set variable_3sets a field, e.g.,variable_3to5678.Set variable_1to Input 1 of the Merge node.Set variable_2to Input 2 of the Merge node.Set variable_3to Input 3 of the Merge node.Output_Node) connected after the Merge node.Output_Node, create a fieldfinal_variable_1with the expression:{{ $('Set variable_1').item.json.variable_1 }}Output_Node, create a fieldfinal_variable_2with the expression:{{ $('Set variable_2').item.json.variable_2 }}Output_Node, create a fieldfinal_variable_3with the expression:{{ $('Set variable_3').item.json.variable_3 }}Output_Node.Set variable_1(Merge Input 1),final_variable_1will correctly show the value (e.g.,1234).Set variable_2(Merge Input 2),final_variable_2will fail with an error like "ERROR: Can't determine which item to use".final_variable_3.(Attached screenshots show the successful retrieval for
final_variable_1and the error "Can't determine which item to use" forfinal_variable_2when inspecting theOutput_Noderesults for the item originating fromSet variable_2).(Bug Test Workflow JSON):
{ "name": "Bug Test Workflow", "nodes": [ { "parameters": { "numberInputs": 3 }, "type": "n8n-nodes-base.merge", "typeVersion": 3.1, "position": [ 460, 200 ], "id": "92aad872-f96b-4785-a858-cf6ea48ef34c", "name": "Merge", "alwaysOutputData": true }, { "parameters": { "assignments": { "assignments": [ { "id": "63830a30-a4cc-4a66-9d01-8f0a058d4d43", "name": "variable_1", "value": "1234", "type": "string" } ] }, "options": {} }, "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ 160, 0 ], "id": "54eaa8ed-b3e8-4c59-af23-9c74d0f15f95", "name": "Set variable_1" }, { "parameters": { "assignments": { "assignments": [ { "id": "63830a30-a4cc-4a66-9d01-8f0a058d4d43", "name": "variable_2", "value": "2345", "type": "string" } ] }, "options": {} }, "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ 160, 200 ], "id": "d3ecaea8-e30c-4911-9adf-78e12df5a7ac", "name": "Set variable_2" }, { "parameters": { "assignments": { "assignments": [ { "id": "63830a30-a4cc-4a66-9d01-8f0a058d4d43", "name": "variable_3", "value": "3456", "type": "string" } ] }, "options": {} }, "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ 160, 400 ], "id": "2e65f7a3-d1f8-44b4-9199-671ba502dd2e", "name": "Set variable_3" }, { "parameters": { "assignments": { "assignments": [ { "id": "ed13172d-9bae-4b21-b168-577eee217e24", "name": "final_variable_1", "value": "={{ $('Set variable_1').item.json.variable_1 }}", "type": "string" }, { "id": "7a92607d-d2f1-4b38-855f-4ec19b70f414", "name": "final_variable_2", "value": "={{ $('Set variable_2').item.json.variable_2 }}", "type": "string" }, { "id": "89862e7d-0c44-4d6a-897e-a249c06f6346", "name": "final_variable_3", "value": "={{ $('Set variable_3').item.json.variable_3 }}", "type": "string" } ] }, "options": {} }, "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ 680, 200 ], "id": "898d35e4-42a7-4fad-8a01-3f0d6d966cab", "name": "Output" }, { "parameters": {}, "type": "n8n-nodes-base.manualTrigger", "typeVersion": 1, "position": [ -140, 200 ], "id": "12501aa5-502f-4960-a44a-833d017a6eb7", "name": "Manual Trigger" } ], "pinData": {}, "connections": { "Merge": { "main": [ [ { "node": "Output", "type": "main", "index": 0 } ] ] }, "Set variable_1": { "main": [ [ { "node": "Merge", "type": "main", "index": 0 } ] ] }, "Set variable_2": { "main": [ [ { "node": "Merge", "type": "main", "index": 1 } ] ] }, "Set variable_3": { "main": [ [ { "node": "Merge", "type": "main", "index": 2 } ] ] }, "Manual Trigger": { "main": [ [ { "node": "Set variable_2", "type": "main", "index": 0 } ] ] } }, "active": false, "settings": { "executionOrder": "v1" }, "versionId": "a3cd04e1-304b-4752-8989-d299c622495c", "meta": { "instanceId": "b7c05a8986e66772aa7af4004a000d6c3b16ca93d88d75938718485e254b5a15" }, "id": "QNCbSmpQ2GNK0w3R", "tags": [] }Expected behavior
The expressions
{{ $('Set variable_2').item.json.variable_2 }}and{{ $('Set variable_3').item.json.variable_3 }}(and similar references to upstream nodes connected to non-first inputs of the Merge node) should correctly resolve and return the values set in their respective source nodes.The behavior should be consistent for all items passing through the Merge node, regardless of which input they came from, and match the behavior of n8n v1.82.2.
Operating System
Ubuntu 22.04.5
n8n Version
1.94.1
Node.js Version
18.19.1
Database
PostgreSQL
Execution mode
queue