Skip to content

User.ransack(age_eq: 123456789012345678901).result raises ActiveModel::RangeError #1337

@JunichiIto

Description

@JunichiIto

Large number in params can raise ActiveModel::RangeError. This issue was already discussed here: #1064

I wrote a test to reproduce this error:

require "test_helper"

class UserTest < ActiveSupport::TestCase
  test "ActiveModel::RangeError" do
    user = users(:one)
    assert_equal [user], User.where(age: 10) # pass
    assert_equal [user], User.ransack(age_eq: 10).result # pass

    assert_equal [], User.where(age: 123456789012345678901) # pass
    assert_equal [], User.ransack(age_eq: 123456789012345678901).result
    #=> ActiveModel::RangeError: 123456789012345678901 is out of range for ActiveRecord::ConnectionAdapters::SQLite3Adapter::SQLite3Integer with limit 8 bytes
  end
end

However, I hope Ransack could return [] like ActiveRecord.

My code is here so you can run it: https://github.com/JunichiIto/ransack-range-error-sandbox/blob/main/test/models/user_test.rb

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions