mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Prevent RangeError
for FinderMethods#exists?
`FinderMethods#exists?` should return a boolean rather than raising an
exception.
`UniquenessValidator#build_relation` catches a `RangeError` because it
includes type casting due to a string value truncation. But a string
value truncation was removed at #23523 then type casting in
`build_relation` is no longer necessary. aa06231
removes type casting in
`build_relation` then a `RangeError` moves to `relation.exists?`.
This change will remove the catching a `RangeError`.
This commit is contained in:
parent
aa062318c4
commit
1cf467b7a3
3 changed files with 5 additions and 6 deletions
|
@ -333,6 +333,8 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
connection.select_value(relation, "#{name} Exists", relation.bound_attributes) ? true : false
|
||||
rescue RangeError
|
||||
false
|
||||
end
|
||||
|
||||
# This method is called whenever no records are found with either a single
|
||||
|
@ -579,7 +581,7 @@ module ActiveRecord
|
|||
# e.g., reverse_order.offset(index-1).first
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def find_nth_with_limit_and_offset(index, limit, offset:) # :nodoc:
|
||||
|
|
|
@ -32,7 +32,6 @@ module ActiveRecord
|
|||
|
||||
record.errors.add(attribute, :taken, error_options)
|
||||
end
|
||||
rescue RangeError
|
||||
end
|
||||
|
||||
protected
|
||||
|
|
|
@ -173,11 +173,9 @@ class FinderTest < ActiveRecord::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_exists_fails_when_parameter_has_invalid_type
|
||||
assert_raises(ActiveModel::RangeError) do
|
||||
assert_equal false, Topic.exists?(("9"*53).to_i) # number that's bigger than int
|
||||
end
|
||||
def test_exists_returns_false_when_parameter_has_invalid_type
|
||||
assert_equal false, Topic.exists?("foo")
|
||||
assert_equal false, Topic.exists?(("9"*53).to_i) # number that's bigger than int
|
||||
end
|
||||
|
||||
def test_exists_does_not_select_columns_without_alias
|
||||
|
|
Loading…
Reference in a new issue