Fix _discard leaking into SQL for multi-select enum filters#3738
Open
tonekk wants to merge 1 commit into
Open
Conversation
_discard leaking into SQL for multi-select enum filters
tonekk
force-pushed
the
fix/discard-leaks-into-sql-for-multiselect-enum-filters
branch
5 times, most recently
from
April 11, 2026 13:46
9d5771f to
49f3392
Compare
When an enum filter is used in multi-select mode, _discard gets
submitted as a literal value on subsequent page loads, producing
invalid SQL like: WHERE (col IN ('_discard','val1','val2'))
Client-side: deselect _discard option when initializing multi-select.
Server-side: strip _discard from array values as defense-in-depth.
tonekk
force-pushed
the
fix/discard-leaks-into-sql-for-multiselect-enum-filters
branch
from
April 11, 2026 14:04
49f3392 to
721bce4
Compare
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.
Summary
When an enum filter is used in multi-select mode,
_discard(the"..."placeholder) gets submitted as a literal value on subsequent page loads, producing SQL like:This PR fixes both the client-side and server-side causes.
Steps to reproduce
roleonUser)adminandeditor) and submit the filter_discardappears as a value in theIN (...)clauseRoot cause
Client-side (
src/rails_admin/filter-box.js): When restoring a multi-select filter on page reload,_discardremains implicitly selected because.prop("multiple", true)preserves the default selection, and the code only hides the option without deselecting it.Server-side (
lib/rails_admin/abstract_model.rb): The_discardguard only checks scalar equality (v == '_discard'), which is always false when@valueis an array like['_discard', 'admin', 'editor'].Fix
.prop("selected", false)when hiding special options in multi-select mode_discardfrom array values as defense-in-depth; return nil if the array becomes empty after stripping