Skip to content

Skip empty-string selected values in lazy Select (#3136) - #3137

Open
wakqasahmed wants to merge 1 commit into
orchidsoftware:masterfrom
wakqasahmed:fix/lazy-select-empty-value-query
Open

Skip empty-string selected values in lazy Select (#3136)#3137
wakqasahmed wants to merge 1 commit into
orchidsoftware:masterfrom
wakqasahmed:fix/lazy-select-empty-value-query

Conversation

@wakqasahmed

Copy link
Copy Markdown
Contributor

Fixes #3136.

ChoicePayload::selectedItems() runs whereIn($key, $keys) unconditionally, even when the incoming selected value is an empty string. That happens for real whenever a lazy Select field is redisplayed after a failed validation and old() 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, and MatrixTest.php — all green. Also ran Pint on the touched files.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Lazy Select field errors when selected value is an empty string

1 participant