From 66023eccb66f327d174685686f98955030d820f2 Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Sat, 16 Jan 2016 13:03:07 +0530 Subject: Fix ActiveRecord::Relation#cache_key for relations with no results - When relations return no result or 0 result then cache_key should handle it gracefully instead of blowing up trying to access `result[:size]` and `result[:timestamp]`. - Fixes #23063. --- activerecord/lib/active_record/collection_cache_key.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/collection_cache_key.rb b/activerecord/lib/active_record/collection_cache_key.rb index b0e555038e..b20df1c232 100644 --- a/activerecord/lib/active_record/collection_cache_key.rb +++ b/activerecord/lib/active_record/collection_cache_key.rb @@ -19,8 +19,14 @@ module ActiveRecord .unscope(:order) result = connection.select_one(query) - size = result["size"] - timestamp = column_type.deserialize(result["timestamp"]) + if result.blank? + size = 0 + timestamp = nil + else + size = result["size"] + timestamp = column_type.deserialize(result["timestamp"]) + end + end if timestamp -- cgit v1.2.3