Skip to content

fix(core): Return pluck() values in the order of the requested fields - #41486

Open
kevin9327 wants to merge 1 commit into
n8n-io:masterfrom
kevin9327:fix/array-pluck-field-order
Open

kevin9327 wants to merge 1 commit into
n8n-io:masterfrom
kevin9327:fix/array-pluck-field-order

Conversation

@kevin9327

@kevin9327 kevin9327 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Array.pluck() with more than one field now returns each item's values in the order of the field names passed in. Before this change it used the order of each object's own keys. The fix is applied to both copies of the extension: n8n-workflow and its mirror in @n8n/expression-runtime.

Why

pluck looped over Object.keys(item) first and over the requested fields second. When items had their keys in different orders, the inner arrays didn't line up: [{ lastName: 'Doe', firstName: 'John' }, { firstName: 'Jane', lastName: 'Roe' }].pluck('firstName', 'lastName') returned [["Doe","John"],["Jane","Roe"]]. Now the code loops over the requested fields and only checks that each one is an own enumerable key, so which fields get included doesn't change.

How to test

Evaluate {{ [{ lastName: 'Doe', firstName: 'John' }, { firstName: 'Jane', lastName: 'Roe' }].pluck('firstName', 'lastName') }} in an expression. The result is now [["John","Doe"],["Jane","Roe"]].

I added unit tests to both packages' array-extensions test files. I ran the @n8n/expression-runtime file with vitest: the new test fails before the fix, and all 15 tests pass after it. For n8n-workflow I didn't do a full install, so I checked the same assertion against arrayExtensions.functions.pluck in a scratch setup instead: it fails before the fix and passes after.

Related Linear tickets, Github issues, and Community forum posts

Fixes #41485

Review / Merge checklist

  • I have seen this code, I have run this code, and I take responsibility for this code.
  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with Backport to Beta, Backport to Stable, or Backport to v1 (if the PR is an urgent fix that needs to be backported)

AI assistance: Grok Bot (AI assistant) helped find this bug and write the fix and tests. I reviewed and ran them.

View guided diff

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would not auto-approve. Auto-approval skipped because this PR is from an external contributor.

View guided diff | Re-trigger cubic

@n8n-assistant n8n-assistant Bot added community Authored by a community member core Enhancement outside /nodes-base and /editor-ui triage:pending Waiting to be triaged labels Oct 20, 2026
@n8n-assistant

n8n-assistant Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Hey @kevin9327,

Thank you for your contribution. We appreciate the time and effort you’ve taken to submit this pull request.

Before we can proceed, please ensure the following: • Your PR references the GitHub issue it fixes (or, for feature requests, a link to the corresponding community forum post). • Tests are included for any new functionality, logic changes or bug fixes. • The PR aligns with our contribution guidelines.

Why the linked issue matters: Our teams pick up work from the issue, not from individual pull requests — the issue is what reaches them, with your PR linked to it. So please make sure the issue contains everything needed to judge the change: a clear problem description, reproduction steps, and the expected behaviour. If the issue is thin, add the missing context there rather than only in the PR description.

Regarding new nodes: We no longer accept new nodes directly into the core codebase. Instead, we encourage contributors to follow our Community Node Submission Guide to publish nodes independently.

If your node integrates with an AI service that you own or represent, please email [email protected] and we will be happy to discuss the best approach.

About review timelines: While we plan to review it as soon as possible, we are currently unable to provide an exact timeframe. Our goal is to begin reviews within a month, but this may change depending on team priorities. We will reach out when the review begins.

Please also note that other contributors may have opened pull requests for the same issue. We keep them all open so the reviewing team can choose the approach that fits best. Once the issue is resolved, the remaining pull requests are closed — this is not a judgement on the quality of your work, and we're grateful for it either way.

Thank you again for contributing to n8n.

1 similar comment
@n8n-assistant

n8n-assistant Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Hey @kevin9327,

Thank you for your contribution. We appreciate the time and effort you’ve taken to submit this pull request.

Before we can proceed, please ensure the following: • Your PR references the GitHub issue it fixes (or, for feature requests, a link to the corresponding community forum post). • Tests are included for any new functionality, logic changes or bug fixes. • The PR aligns with our contribution guidelines.

Why the linked issue matters: Our teams pick up work from the issue, not from individual pull requests — the issue is what reaches them, with your PR linked to it. So please make sure the issue contains everything needed to judge the change: a clear problem description, reproduction steps, and the expected behaviour. If the issue is thin, add the missing context there rather than only in the PR description.

Regarding new nodes: We no longer accept new nodes directly into the core codebase. Instead, we encourage contributors to follow our Community Node Submission Guide to publish nodes independently.

If your node integrates with an AI service that you own or represent, please email [email protected] and we will be happy to discuss the best approach.

About review timelines: While we plan to review it as soon as possible, we are currently unable to provide an exact timeframe. Our goal is to begin reviews within a month, but this may change depending on team priorities. We will reach out when the review begins.

Please also note that other contributors may have opened pull requests for the same issue. We keep them all open so the reviewing team can choose the approach that fits best. Once the issue is resolved, the remaining pull requests are closed — this is not a judgement on the quality of your work, and we're grateful for it either way.

Thank you again for contributing to n8n.

@n8n-assistant n8n-assistant Bot added triage:in-progress Triage is in progress bug triage:complete Triage has been completed and issue is ready for internal teams triage:ready-for-review and removed triage:pending Waiting to be triaged triage:in-progress Triage is in progress bug labels Oct 20, 2026

@ManyaS-Git ManyaS-Git left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey @kevin9327, nice catch and great explanation of the bug in #41485! Looping over extraArgs so output values align with the requested field order makes total sense and prevents unexpected tuple misalignment across items with different key insertion orders.

A few observations and suggestions from reviewing the diff:

1. Avoiding new Set(Object.keys(current)) allocations on every item

Inside value.reduce, calling const keys = new Set(Object.keys(current)) allocates a new string array and a Set instance for each item in value:

const keys = new Set(Object.keys(current));
(extraArgs as string[]).forEach((field) => {
	if (keys.has(field)) {
		p.push((current as { [key: string]: unknown })[field]);
	}
});

When plucking large datasets (e.g. workflows with thousands of items), this creates unnecessary memory churn and GC pressure. Using Object.prototype.hasOwnProperty.call(current, field) (or Object.hasOwn(current, field)) checks whether field is an own property in O(1) time without any per-item allocations.

2. Handling numeric property keys

Set.has() uses strict equality (SameValueZero), whereas property access coerces keys to strings. If a workflow calls .pluck(0, 1) or accesses numeric keys on tuple-like items, Object.keys(current) produces string keys (['0', '1']), so keys.has(0) evaluates to false. In contrast, Object.prototype.hasOwnProperty.call(current, field) coerces the argument, preserving numeric key support.

3. Test consistency with expression evaluation

In packages/workflow/test/ExpressionExtensions/array-extensions.test.ts, the neighboring tests use the evaluate("={{ [...] }}") helper to verify end-to-end expression parsing and execution together. How about using evaluate() for the new test case as well to keep test conventions consistent with the rest of the suite?

WDYT? 🙂

@kevin9327

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @ManyaS-Git.

  1. Allocation: fair point. The Set is built once per item, so it is O(fields + keys) per item, the same order as the nested loops it replaces. Object.hasOwn(current, field) would avoid it; I am happy to switch if the maintainers prefer that.
  2. Numeric keys: no change in behaviour here. The previous code compared field === k against the strings from Object.keys(), so .pluck(0) did not match before either. Making numeric field names work would be a separate behaviour change, so I kept it out of this fix.
  3. Tests: the new tests call pluck directly so that they pin the order of the returned values without going through expression parsing; the neighbouring evaluate() tests still cover the end-to-end path.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed community Authored by a community member core Enhancement outside /nodes-base and /editor-ui triage:complete Triage has been completed and issue is ready for internal teams triage:ready-for-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Array .pluck() with several fields returns values in object key order, not the requested field order

2 participants