Skip to content

Improvement: check validity for (Multi)Select before setting values#17742

Merged
kingjia90 merged 19 commits intopimcore:12.xfrom
samynw:fix/17343-validate-select-values
Dec 4, 2025
Merged

Improvement: check validity for (Multi)Select before setting values#17742
kingjia90 merged 19 commits intopimcore:12.xfrom
samynw:fix/17343-validate-select-values

Conversation

@samynw
Copy link
Copy Markdown
Contributor

@samynw samynw commented Oct 18, 2024

Changes in this pull request

As described in issue #17343, when using the Pimcore API, any value can be set on a select or multiselect field. This improvement checks the validity before setting the data by matching the value against the allowed options.

If the given data is not allowed, a ValidationException will be thrown.

Additional info

The validity check supports:

  • configured options
  • SelectOptions
  • OptionProvider

Resolves: #17343

When using the Pimcore API, any value can be set on a select or
multiselect field. This improvement checks the validity before setting
the data.

It applies to configured options, SelectOptions and OptionProviders.

Resolves: pimcore#17343
@github-actions
Copy link
Copy Markdown

Review Checklist

  • Target branch (11.4 for bug fixes, others 11.x)
  • Tests (if it's testable code, there should be a test for it - get help)
  • Docs (every functionality needs to be documented, see here)
  • Migration incl. install.sql (e.g. if the database schema changes, ...)
  • Upgrade notes (deprecations, important information, migration hints, ...)
  • Label
  • Milestone

@github-actions
Copy link
Copy Markdown

github-actions bot commented Oct 18, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@samynw
Copy link
Copy Markdown
Contributor Author

samynw commented Oct 18, 2024

I have read the CLA Document and I hereby sign the CLA

@samynw samynw marked this pull request as draft October 18, 2024 15:19
samynw and others added 6 commits October 22, 2024 17:57
In case no list of options is defined (yet), don't validate the new
input value. This avoids large volume of ValidationErrors when for
example a SelectOption or OptionsProvider service gets missing
- use actual values instead of numbers for the MultiSelect fields (as
  the Country and Language (single) Select already do)
- fix the faulty assert for LanguageMultiSelect (which was using the
  CountryMultiSelect assert)
As the return type is nullable, this should be indicated by the doc
block as well.
As the options were already checked for being empty, the array will
never need a fallback at this point
@samynw samynw marked this pull request as ready for review October 22, 2024 19:16
@ghost ghost added the Pimcore:ToDo label Oct 23, 2024
samynw and others added 2 commits October 23, 2024 16:10
Co-authored-by: Sebastian Blank <sebastian.bl@gmx.de>
Co-authored-by: Sebastian Blank <sebastian.bl@gmx.de>
@sonarqubecloud
Copy link
Copy Markdown

@samynw samynw requested a review from blankse October 23, 2024 14:43
@kingjia90 kingjia90 self-assigned this Aug 12, 2025
Copy link
Copy Markdown
Contributor

@kingjia90 kingjia90 left a comment

Choose a reason for hiding this comment

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

My concern from a bigger picture is that (feels like) the former behavior was kind of intended, at least for existing data:

  • Given A,B,C, if one picks A,B,C and save.
  • Temporary remove C from available options.
  • Try to save object again without any changes

Before PR, C would "disappear" from the UI list, but if one restores the option with the same name, then it would be there again as selected (because the value matches). Overall no any blocks from saving or usual editing.
After PR, C is not removable from UI perspective and the object is stuck forever (can't save, as it doesn't clear the invalid option and keeps throwing exception), until someone overwrite the set value via API.

Maybe we need to refactor to something more limited to API, of ex-novo objects (on setter with empty existing selection) and/or may need some more insights from @fashxp @brusch first

@brusch
Copy link
Copy Markdown
Member

brusch commented Aug 14, 2025

@kingjia90 @samynw What do you guys think about making the behavior configurable?
So an option in the config of the select data-types to enforce validity or not.
This would have the benefit of being a non-breaking change, as we can keep the current behavior as the default, and would also cover the topic outlined by @kingjia90 above.

WDYT?

@kingjia90
Copy link
Copy Markdown
Contributor

kingjia90 commented Aug 14, 2025

@kingjia90 @samynw What do you guys think about making the behavior configurable? So an option in the config of the select data-types to enforce validity or not. This would have the benefit of being a non-breaking change, as we can keep the current behavior as the default, and would also cover the topic outlined by @kingjia90 above.

WDYT?

Thank you @brusch for having a look and the feedback, to me it sounds good, a sort of strict mode that also takes care of the redundant/orphanized data (and remove the not visible data and in-existing options), configurable at a single data type field level

@kingjia90 kingjia90 marked this pull request as draft August 27, 2025 10:02
@kingjia90
Copy link
Copy Markdown
Contributor

@samynw 🏓 Could you please have a look the latest feedbacks and apply the changes? Thank you in advance

@kingjia90
Copy link
Copy Markdown
Contributor

Any updates? Please let me know if i should take over and apply the requested changes of making it configurable, TIA

@samynw
Copy link
Copy Markdown
Contributor Author

samynw commented Nov 12, 2025

@kingjia90 Thank you for your feedback. You make a valid point and your example topic makes sense. I agree with you, and the suggestion of @brusch to make it configurable is definitely the best approach.

However, I'm currently limited in availability to apply the suggested changes, so @kingjia90 feel free to take over if you are still up for it, that would be great!

@kingjia90
Copy link
Copy Markdown
Contributor

Tests looks working fine
image
f14a477

@kingjia90 kingjia90 marked this pull request as ready for review December 2, 2025 12:51
@kingjia90 kingjia90 added this to the 12.3.0 milestone Dec 2, 2025
@kingjia90 kingjia90 requested a review from blankse December 3, 2025 09:22
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Dec 4, 2025

@kingjia90 kingjia90 merged commit 8d3af10 into pimcore:12.x Dec 4, 2025
14 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Dec 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Select/Multiselect fields accept invalid data

6 participants