Skip empty-string selected values in lazy Select (#3136) - #3137
Open
wakqasahmed wants to merge 1 commit into
Open
Skip empty-string selected values in lazy Select (#3136)#3137wakqasahmed wants to merge 1 commit into
wakqasahmed wants to merge 1 commit into
Conversation
Select::lazy() field can end up with an empty string as its selected
value (e.g. old('field') after a failed validation on a select left
empty). ChoicePayload::selectedItems() ran whereIn() with that blank
value anyway, which fails on strict-typed primary key columns like
Postgres bigint. Filter out null/empty keys before querying, same as
the earlier Matrix field fix in orchidsoftware#3040.
Fixes orchidsoftware#3136.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3136.
ChoicePayload::selectedItems()runswhereIn($key, $keys)unconditionally, even when the incoming selected value is an empty string. That happens for real whenever a lazySelectfield is redisplayed after a failed validation andold()returns""for a select the user left empty. On a strict-typed PK column (Postgres bigint, for example) that query blows up instead of just showing no selection. Same bug class as the Matrix/Relation fix in #3040, just resurfaced in the new unified Select field's lazy path.Filtered out null/empty-string keys before building the query, and skip the query entirely if nothing's left. Added a test asserting no query runs for a blank value (fails before the fix, since the old code always hits the DB), plus one covering a null mixed into a real selected value.
Ran
tests/Unit/Screen/Fields/ChoicePayloadTest.php,SelectTest.php,SelectWithEnumTest.php, andMatrixTest.php— all green. Also ran Pint on the touched files.