Skip to content

fix: preserve nested arrays in transformPointDataToPayload - #19440

Open
quandes wants to merge 1 commit into
payloadcms:mainfrom
quandes:fix/transform-point-data-nested-arrays
Open

quandes wants to merge 1 commit into
payloadcms:mainfrom
quandes:fix/transform-point-data-nested-arrays

Conversation

@quandes

@quandes quandes commented Nov 8, 2026

Copy link
Copy Markdown

What?

transformPointDataToPayload (used by the MCP create/update/duplicate tools and the data CLI) turns nested arrays into index-keyed objects:

transformPointDataToPayload({ points: [[0, 0], [1, 0]] })
// before: { points: [{ '0': 0, '1': 0 }, { '0': 1, '1': 0 }] }
// after:  { points: [[0, 0], [1, 0]] }

Why?

Array items are forwarded to transformPointDataToPayload whenever typeof item === 'object', which is also true for arrays. The inner array is then rebuilt via Object.entries().

Any nested array in tool input data is affected, e.g. coordinate or polygon lists stored in a json field. In our case, an MCP update of a page whose block holds a shape definition in a json field failed the field's validation, while the identical data passed when written through the Local API.

How?

Arrays are mapped recursively through a small transformArray helper: inner arrays stay arrays, objects inside arrays still go through transformPointDataToPayload, primitives and null pass through unchanged. Point conversion ({ longitude, latitude } → [longitude, latitude]) is untouched.

Added transformPointDataToPayload.spec.ts covering point conversion (top level and inside arrays), nested arrays and null/primitive items. The two new cases fail on current main and pass with this change.

The same code exists on 3.x in packages/plugin-mcp/src/utils/transformPointDataToPayload.ts (we hit it on 3.85.0 and currently patch it via pnpm patch). Happy to open a backport PR against 3.x if that's useful.

🤖 Generated with Claude Code

Array items were passed to transformPointDataToPayload whenever
`typeof item === 'object'`, which is also true for arrays. Inner arrays were
then rebuilt via Object.entries() and turned into index-keyed objects, e.g.
[[0, 0], [1, 0]] became [{ '0': 0, '1': 0 }, { '0': 1, '1': 0 }].

This corrupts any nested array in tool input data, such as coordinate lists
stored in json fields, so MCP create/update calls either fail validation or
store the wrong shape. Map arrays recursively instead; point conversion and
null handling are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

transformPointDataToPayload now recursively transforms nested arrays while preserving their structure. Tests cover point objects, nested arrays, nulls, and primitive array items.

Changes: Point Data Transformation

Layer / File(s) Summary
Recursive array transformation
packages/payload/src/utilities/transformPointDataToPayload.ts, packages/payload/src/utilities/transformPointDataToPayload.spec.ts
Array-valued fields use a recursive helper. It preserves nested arrays, transforms object items, and retains primitive items. Tests cover point objects, nested arrays, nulls, and primitives.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: kendelljoseph

Merge Risk: Minimal · up to 1fca9

The change preserves nested array structure without an identified merge-blocking regression. Merge after normal checks.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title names the specific fix: nested arrays in transformPointDataToPayload are now preserved instead of being converted into index-keyed objects. This matches the main change in both the source fi…
Description check Passed The description states the problem (nested arrays turned into index-keyed objects), the cause (array items routed through the object transformer and rebuilt via Object.entries()), the fix (a recursive…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the specific fix: nested arrays in transformPointDataToPayload are now preserved instead of being converted into index-keyed objects. This matches the main change in both the source file and the spec file, so the title is related to the changeset.

Full details: Description check

Explanation

The description states the problem (nested arrays turned into index-keyed objects), the cause (array items routed through the object transformer and rebuilt via Object.entries()), the fix (a recursive transformArray helper), and the new spec coverage. It fits the changeset closely.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 25dfb24 and 1fca913.

Files selected for processing: 2

  • packages/payload/src/utilities/transformPointDataToPayload.spec.ts
  • packages/payload/src/utilities/transformPointDataToPayload.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant