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(Merge Node): Fixing how paired items are handled in the merge node, when choosing a branch and selecting to return an empty object #8479

Merged
merged 3 commits into from
Feb 13, 2024

Conversation

despairblue
Copy link
Contributor

@despairblue despairblue commented Jan 29, 2024

Summary

Referencing items before a merge node was broken when you chose to return a single empty object due to how the paired items were handled.

I stumbled on this while attempting to solve the level 2 course.

Related tickets and issues

Include links to Linear ticket or Github issue or Community forum post. Important in order to close automatically and provide context to reviewers.

Review / Merge checklist

  • PR title and summary are descriptive. Remember, the title automatically goes into the changelog. Use (no-changelog) otherwise. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.

    A bug is not considered fixed, unless a test is added to prevent it from happening again.
    A feature is not complete without tests.

This happens only when choosing a branch and selecting to return an empty object.

I stumbled on this while attempting to solve the level 2 course.
@n8n-assistant n8n-assistant bot added n8n team Authored by the n8n team node/improvement New feature or request labels Jan 29, 2024
@despairblue despairblue changed the title fix paired items handling in the merge node This happens only when choosing a branch and selecting to return an empty object. fix(Merge Node): Paired items handling in the merge node, when choosing a branch and selecting to return an empty object Feb 13, 2024
@despairblue despairblue force-pushed the fix-paired-items-being-broken-merge-node branch from c00c8db to 26c00b1 Compare February 13, 2024 09:41
Comment on lines 607 to 626
// TODO: was necessary to satisfies types.
// I'm wondering if there is already a function that does exactly that? That turns
// Array<IPairedItemData | IPairedItemData[] | number | undefined> -> IPairedItemData[]
// or
// IPairedItemData | IPairedItemData[] | number | undefined -> IPairedItemData | undefined
function numberToPairedItem(
possiblyPairedItems: Array<INodeExecutionData['pairedItem']>,
): IPairedItemData[] {
return possiblyPairedItems.reduce((pairedItems: IPairedItemData[], pairedItem) => {
if (typeof pairedItem === 'number') {
pairedItems.push({ item: pairedItem });
} else if (Array.isArray(pairedItem)) {
pairedItems.push(...pairedItem);
} else if (pairedItem) {
pairedItems.push(pairedItem);
}

return pairedItems;
}, [] as IPairedItemData[]);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a better way to do this?
Does this helper exist anywhere? If not, should I move it to some utility module?

Copy link
Member

Choose a reason for hiding this comment

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

@despairblue I guess if this is something that may come up again it would be handy to have a utility function for it so we can reuse it but I am not sure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Joffcom There was a function already that does this, just had to combine it with a flatMap :)

@despairblue despairblue marked this pull request as ready for review February 13, 2024 09:42
@despairblue despairblue requested a review from Joffcom February 13, 2024 11:43
Copy link
Contributor

@michael-radency michael-radency left a comment

Choose a reason for hiding this comment

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

LGTM

@despairblue despairblue changed the title fix(Merge Node): Paired items handling in the merge node, when choosing a branch and selecting to return an empty object fix(Merge Node): Fixing how paired items are handled in the merge node, when choosing a branch and selecting to return an empty object Feb 13, 2024
Copy link
Contributor

✅ All Cypress E2E specs passed

Copy link

cypress bot commented Feb 13, 2024

1 flaky test on run #4088 ↗︎

0 343 5 0 Flakiness 1

Details:

🌳 🖥️ browsers:node18.12.0-chrome107 🤖 despairblue 🗃️ e2e/*
Project: n8n Commit: bafcdd2dc9
Status: Passed Duration: 03:29 💡
Started: Feb 13, 2024 1:45 PM Ended: Feb 13, 2024 1:49 PM
Flakiness  cypress/e2e/5-ndv.cy.ts • 1 flaky test

View Output Video

Test Artifacts
NDV > should not retrieve remote options when required params throw errors Test Replay Screenshots Video

Review all test suite changes for PR #8479 ↗︎

@despairblue despairblue merged commit a3bed97 into master Feb 13, 2024
29 of 30 checks passed
@despairblue despairblue deleted the fix-paired-items-being-broken-merge-node branch February 13, 2024 14:00
@github-actions github-actions bot mentioned this pull request Feb 15, 2024
@janober
Copy link
Member

janober commented Feb 15, 2024

Got released with [email protected]

despairblue added a commit that referenced this pull request Feb 16, 2024
…e, when choosing a branch and selecting to return an empty object (#8479)

Co-authored-by: Michael Kret <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
n8n team Authored by the n8n team node/improvement New feature or request Released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants