Skip to content

Fix: blank filter values no longer activate their filter (1.2.1) - #92

Merged
bunnrf merged 1 commit into
mainfrom
fix-blank-filter-activation
Aug 10, 2026
Merged

Fix: blank filter values no longer activate their filter (1.2.1)#92
bunnrf merged 1 commit into
mainfrom
fix-blank-filter-activation

Conversation

@bunnrf

@bunnrf bunnrf commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Why

1.2.0 changed Filtrator#active_filters so a filter activates whenever its param key is present, regardless of the value. This means a blank value (nil, "", []) now activates the filter — which the pre-1.2 code deliberately skipped.

In practice that turns an empty filter into a real SQL predicate:

  • WHERE col = '' — harmless on some string columns, but a 500 (PG::InvalidTextRepresentation) on integer / uuid columns.
  • WHERE col IN () — unintended narrowing to zero rows.
  • undefined scopes invoked with a blank arg — NoMethodError.

Blank filter values are extremely common (a UI sends filters[status]= for an unselected dropdown), so consumers on 1.2.0 see production errors on ordinary requests.

What

Restore the pre-1.2 rule that a blank value leaves its filter inactive, while keeping the 1.2.0 fix that a literal boolean false is a meaningful, active value (#58).

active_filters now activates a filter only when:

value == false || value.present?

so false still filters, but nil / "" / [] no longer do.

Testing

  • Added a Filtrator test asserting blank values ("", nil, []) leave the filter inactive and return the full collection. This fails on 1.2.0 and passes here.
  • The existing "filters by boolean field even when the value is false" test still passes, guarding the Fix filter by boolean field #58 behavior.

Bumps the version to 1.2.1 and adds a CHANGELOG entry.

1.2.0 activated a filter whenever its param key was present, so an empty value (nil/""/[]) produced conditions like `WHERE col = ''` — a 500 on integer/uuid columns and unintended narrowing elsewhere. Skip blank values again while still honoring a literal `false` (preserves #58).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@bunnrf
bunnrf marked this pull request as ready for review August 10, 2026 15:55
@bunnrf
bunnrf requested a review from a team as a code owner August 10, 2026 15:55
@bunnrf
bunnrf merged commit 437be19 into main Aug 10, 2026
10 of 11 checks passed
@bunnrf
bunnrf deleted the fix-blank-filter-activation branch August 10, 2026 18:16
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