Skip to content

Leave boolean predicates out of a value policy - #6

Merged
Fivell merged 1 commit into
mainfrom
leave-boolean-predicates-unpoliced
Oct 19, 2026
Merged

Fivell merged 1 commit into
mainfrom
leave-boolean-predicates-unpoliced

Conversation

@Fivell

@Fivell Fivell commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

The bug

A value policy (sanitize: / validate:) swept every request key naming its attribute, including the predicates Ransack answers with a boolean rather than with a value of the column's own type — null, not_null, present, blank.

So for

filter :position_eq, extensions: { sanitize: :digits, validate: :integer }

a request of ?q[position_null]=true went: "true" → :digits → "" → :integer refuses → :reset drops the key → the redirect lands on the bare index. A link meaning "the rows with no position set" came back as the whole table, silently including the rest.

The fix

sibling_predicate_keys now skips a sibling whose Ransack predicate is of type :boolean, asking Ransack itself (Ransack::Predicate.named(...).type) rather than matching suffixes, so an app's own boolean predicate is covered too.

A boolean predicate the filter declares stays policed — filter :x_null, extensions: { validate: ... } is a policy its author asked for, and the derived key is still in keys.

Test

spec/integration/numeric_builtins_spec.rb, under "sibling predicates" — a post with no position, fetched through ?q[position_null]=true on the IntegerPost resource whose position_eq carries both numeric policies.

Red before the fix:

expected: {"position_null"=>"true"}
     got: nil

(the whole q was gone — the condition had been dropped). Green after. Full suite: 196 examples, 0 failures.

Version bumped to 1.0.1.

A value policy swept every request key naming its attribute, boolean predicates
included. `?q[customer_id_null]=true` is answered by "true", not by a value of
the column's own type: `sanitize: :digits` emptied it, `validate: :integer`
refused what was left, and the :reset dropped the key - so a drill-down link
that spelled out "no customer" came back as the whole table.

The sweep now skips a sibling whose Ransack predicate is of type :boolean
(`null`, `not_null`, `present`, `blank`). A boolean predicate the filter
declares itself stays policed: that one its author asked for.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused fix and regression test have no identified blocking issues; tests were not executed during review.

No open issues 🎉

What changed in this PR

Prevents value policies from dropping boolean sibling predicates while preserving enforcement for explicitly declared predicates.

Changes:

  • Uses Ransack predicate types to exclude boolean siblings.
  • Adds a regression test for position_null=true.
  • Bumps the version to 1.0.1.
File Description
spec/​integration/​numeric_builtins_spec.rb Tests preservation of boolean sibling filtering.
lib/​active_admin_filter_extensions/​version.rb Updates the version to 1.0.1.
lib/​active_admin_filter_extensions/​policies.rb Excludes undeclared boolean siblings from value policies.

Review effort: Balanced

@Fivell
Fivell merged commit 9cdbd65 into main Oct 19, 2026
7 checks passed
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.

2 participants