Skip to content

RangeError when querying for big integer using #where in Rails 4.2 #21309

@januszm

Description

@januszm

Rails 3

Product.where(associated_id: 1311344470881970878875083923).first
=> nil

Rails 4.2.3

Product.where(associated_id: 1311344470881970878875083923).first
RangeError: 1311344470881970878875083923 is out of range for ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Integer with limit 8
from ~/.rvm/gems/ruby-2.2.1@gemset/gems/activerecord-4.2.3/lib/active_record/type/integer.rb:45:in ensure_in_range

I'd expect that the finder returns nothing in Rails 4.2.3 as well in such a case. It's just searching for results, we don't need to call ensure_in_range.

As a workaround, someone could use find_by, but when there's a need for returning multiple records, then there's no such method as find_all_by that could be used. BTW. find_by works because it rescues from RangeError.

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