aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation/finder_methods.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2016-06-04 15:03:47 +0900
committerRyuta Kamizono <kamipo@gmail.com>2016-06-16 06:25:37 +0900
commit1cf467b7a31749ccb3fc2a8ac89c5218c95e7d70 (patch)
tree55bd2830a231d521b806e76806aabb292b373928 /activerecord/lib/active_record/relation/finder_methods.rb
parentaa062318c451512035c10898a1af95943b1a3803 (diff)
downloadrails-1cf467b7a31749ccb3fc2a8ac89c5218c95e7d70.tar.gz
rails-1cf467b7a31749ccb3fc2a8ac89c5218c95e7d70.tar.bz2
rails-1cf467b7a31749ccb3fc2a8ac89c5218c95e7d70.zip
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`.
Diffstat (limited to 'activerecord/lib/active_record/relation/finder_methods.rb')
-rw-r--r--activerecord/lib/active_record/relation/finder_methods.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/finder_methods.rb b/activerecord/lib/active_record/relation/finder_methods.rb
index 87eea8277a..0948e55ae3 100644
--- a/activerecord/lib/active_record/relation/finder_methods.rb
+++ b/activerecord/lib/active_record/relation/finder_methods.rb
@@ -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: