Skip to content

Non-boolean values passed to boolean predicates are no longer cast #1644

@dennmart

Description

@dennmart

The changes made in #1559 changed how values are casted for some/all boolean predicates like not_null.

Before the changes from the PR, when passing a non-boolean value to a boolean predicate (for example: name_not_null = 0), the Ransack::Nodes::Condition#casted_values_for_attribute method would call Ransack::Nodes::Value#cast using the predicate or attribute type. When the predicate type is boolean, the value would be cast to a proper boolean.

The changes in the PR just pass the value directly without any casting, so when calling the arel_predicate proc for the predicate, it will evaluate to true because 0 is truthy. Using a boolean value (like name_not_null = false) works as expected.

I'm not sure if this is a bug and these values should be properly cast, or if we're expected with Ransack 4.4.0 to use boolean values for these types of predicates.

Original issue #1555

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions