Non-boolean values passed to boolean predicates are no longer cast
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 https://github.com/activerecord-hackery/ransack/issues/1555
Same issue here. Version 4.4.0 breaks all my code. Is this a bug or an intentional breaking change?
@matheussilvasantos what are your thoughts on this issue?
Thank you for the report @dennmart and @pioz - this does appear to be a bug. Please also see the request in this issue for a large number of changes coming to Ransack.
Same issue here. Version 4.4.0 breaks all my code. Is this a bug or an intentional breaking change?
Not intentional.
@deivid-rodriguez can help more than me in this case.
Same issue for timestamp column.
app(dev)> Time.zone
=> #<ActiveSupport::TimeZone:0x00007fb8e1a708b8 @name="Tokyo", @tzinfo=#<TZInfo::DataTimezone: Asia/Tokyo>, @utc_offset=nil>
# 4.3.0
app(dev)> puts User.ransack(created_at_gteq: '2025-09-29T00:00').result.to_sql
SELECT "users".* FROM "users" WHERE "users"."created_at" >= '2025-09-28 15:00:00'
# 4.4.0
app(dev)> puts User.ransack(created_at_gteq: '2025-09-29T00:00').result.to_sql
SELECT "users".* FROM "users" WHERE "users"."created_at" >= '2025-09-29 00:00:00'
Hmm I think we have to revert this PR until we can solve it. I will revert it and release v4.4.1 as a patch. See this note https://github.com/activerecord-hackery/ransack/issues/1640#issuecomment-3346334948
If anyone else wants to do a PR to fix it, or just with the failing tests, that would be great.
Reverting with PR https://github.com/activerecord-hackery/ransack/pull/1645 and releasing v4.4.1
Reverting with PR #1645 and releasing v4.4.1
All tests are green. Version 4.4.1 appears to resolve the issue.
I can confirm that the latest release fixes my issue with the boolean predicates 👍
Thanks for the report and quick revert. I'll look into this again, considering this regression 👍.
@deivid-rodriguez I think it is pretty close, this looks like the culprit
I'm actually in between jobs at the moment, I can also take a look at it.
Sure, please go ahead! If when I get to this it's not yet fixed, I can take over the fix wherever you left it 👍.