Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Fix expression with paired item with multi-input node #7424

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions cypress/e2e/24-ndv-paired-item.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,59 @@ describe('NDV', () => {
// todo there's a bug here need to fix ADO-534
// ndv.getters.outputHoveringItem().should('not.exist');
});

it('can resolve expression with paired item in multi-input node', () => {
cy.fixture('expression_with_paired_item_in_multi_input_node.json').then((data) => {
cy.get('body').paste(JSON.stringify(data));
});

workflowPage.actions.zoomToFit();

/* prettier-ignore */
const PINNED_DATA = [
{
"id": "abc",
"historyId": "def",
"messages": [
{
"id": "abc"
}
]
},
{
"id": "abc",
"historyId": "def",
"messages": [
{
"id": "abc"
},
{
"id": "abc"
},
{
"id": "abc"
}
]
},
{
"id": "abc",
"historyId": "def",
"messages": [
{
"id": "abc"
}
]
}
];
/* prettier-ignore */
workflowPage.actions.openNode('Get thread details1');
ndv.actions.setPinnedData(PINNED_DATA);
ndv.actions.close();

workflowPage.actions.executeWorkflow();
workflowPage.actions.openNode('Switch1');
ndv.actions.execute();

ndv.getters.parameterExpressionPreview('output').should('include.text', '1');
});
});
156 changes: 156 additions & 0 deletions cypress/fixtures/expression_with_paired_item_in_multi_input_node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
{
"meta": {
"instanceId": "abc"
},
"nodes": [
{
"parameters": {},
"id": "bcb6abdf-d34b-4ea7-a8ed-58155b708c43",
"name": "When clicking \"Execute Workflow\"",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
20,
260
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field\n// called 'myNewField' to the JSON of each one\nfor (const item of $input.all()) {\nitem.json.message_count = Math.min(item.json.messages.length, 3);\n}\n\nreturn $input.all();"
},
"id": "59c3889c-3671-4f49-b258-6131df8587d8",
"name": "Set thread properties1",
"type": "n8n-nodes-base.code",
"typeVersion": 1,
"position": [
500,
520
]
},
{
"parameters": {
"resource": "thread",
"operation": "get",
"threadId": "={{ $json.id }}",
"options": {}
},
"id": "e102b72e-1e47-4004-a6b9-38cef75f44a1",
"name": "Get thread details1",
"type": "n8n-nodes-base.gmail",
"typeVersion": 2,
"position": [
300,
520
]
},
{
"parameters": {
"mode": "expression",
"output": "={{ $('Set thread properties1').item.json.message_count }}"
},
"id": "f3e42f07-df82-42ba-8e99-97cda707a9d9",
"name": "Switch1",
"type": "n8n-nodes-base.switch",
"typeVersion": 1,
"position": [
1220,
540
]
},
{
"parameters": {
"conditions": {
"boolean": [
{
"value1": true,
"value2": true
}
]
}
},
"id": "c7fe521e-8c02-44bf-8a14-482b39749508",
"name": "IF",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
720,
520
]
},
{
"parameters": {},
"id": "3b9f6a05-7f19-46c5-95d1-5dec732f00ae",
"name": "No Operation, do nothing",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
960,
400
]
}
],
"connections": {
"When clicking \"Execute Workflow\"": {
"main": [
[
{
"node": "Get thread details1",
"type": "main",
"index": 0
}
]
]
},
"Set thread properties1": {
"main": [
[
{
"node": "IF",
"type": "main",
"index": 0
}
]
]
},
"Get thread details1": {
"main": [
[
{
"node": "Set thread properties1",
"type": "main",
"index": 0
}
]
]
},
"IF": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
],
[
{
"node": "Switch1",
"type": "main",
"index": 0
}
]
]
},
"No Operation, do nothing": {
"main": [
[
{
"node": "Switch1",
"type": "main",
"index": 0
}
]
]
}
}
}
6 changes: 3 additions & 3 deletions packages/workflow/src/WorkflowDataProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1044,9 +1044,9 @@ export class WorkflowDataProxy {
});
}

const sourceData: ISourceData = that.executeData.source.main[
pairedItem.input || 0
] as ISourceData;
const sourceData: ISourceData | null =
that.executeData.source.main[pairedItem.input || 0] ??
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't that the same as itemInput?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

itemInput is not in scope at L1048?

that.executeData.source.main[0];

return getPairedItem(nodeName, sourceData, pairedItem);
};
Expand Down
Loading