Skip to content

Allow patching a multiselect to empty - #2020

Open
xIrusux wants to merge 2 commits into
2025.4from
fix-multiselect-patch-replace-null-2025-4
Open

Allow patching a multiselect to empty#2020
xIrusux wants to merge 2 commits into
2025.4from
fix-multiselect-patch-replace-null-2025-4

Conversation

@xIrusux

@xIrusux xIrusux commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Because clearing a multiselect through a merge is a legal operation the core adapter's type signature forbade.

What the merge sent: object 333's color is empty; you chose to pull that side over, so the merger saved color: { action: 'replace', data: null } — "replace the target's value with nothing", i.e. clear the field. That's the correct payload for this merge, not a frontend bug.

Where it exploded: MultiSelectAdapter::handlePatch handles replace by returning the payload's data verbatim — but its return type was declared array, so data: null throws a TypeError and the whole PATCH 500s (MultiSelectAdapter.php:66).

Why widening to ?array is the right fix, not a workaround: the caller already supports null — PatchService::patchEditableData passes the adapter's return straight into $element->setValue($key, $value) with no null check, and setValue(key, null) is Pimcore's normal "clear this field". The add/remove paths in the same adapter also cope with null existing values. Only the replace path's signature was narrower than its own contract. One character (?) restores it.

Verified

  • Reproduced via the object merger (embedded in the backend-power-tools compare & merge wizard): merging an object with an empty multiselect over one with values 500ed; with this change the PATCH clears the field.
  • Regression test added (MultiSelectAdapterTest, following the NumericRangeAdapterTest pattern): replace with data: null returns null, replace with values returns them, non-array input returns null. 3/3 green locally via vendor/bin/codecept run Unit.

🤖 Generated with Claude Code

xIrusux and others added 2 commits August 31, 2026 14:58
A replace patch with data: null ("clear the field") threw a TypeError
because handlePatch declared a non-nullable array return while
returning the payload data verbatim. The caller already supports null:
PatchService passes the adapter result straight into setValue(), where
null is the normal way to clear a field.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings August 31, 2026 12:59
@sonarqubecloud

Copy link
Copy Markdown

Copilot AI 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.

Pull request overview

Allows multiselect PATCH operations to clear fields by accepting null replacement values.

Changes:

  • Widens the patch handler return type to ?array.
  • Adds regression tests for null, populated, and invalid multiselect values.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/DataObject/Data/Adapter/MultiSelectAdapter.php Supports null replacement values.
tests/Unit/DataObject/Data/Adapter/MultiSelectAdapterTest.php Covers multiselect patch behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@xIrusux xIrusux added this to the 2025.4.12 milestone Aug 31, 2026
@xIrusux xIrusux self-assigned this Aug 31, 2026
@xIrusux
xIrusux requested a review from lukmzig August 31, 2026 13:03
@robertSt7 robertSt7 modified the milestones: 2025.4.12, 2025.4.13 Sep 1, 2026
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.

4 participants