From 600a66f60c76cb2d32fbf7abe4e37d509fdade47 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Wed, 2 Jan 2019 04:15:32 +0900 Subject: Fix TypeError: no implicit conversion of Arel::Attributes::Attribute into String properly This reverts 27c6c07 since `arel_attr.to_s` is not right way to avoid the type error. That to_s returns `"#"`, there is no reason to match the regex to the inspect form. And also, the regex path is not covered by our test cases. I've tweaked the regex for redundant part and added assertions for the regex path. --- activerecord/lib/active_record/relation/calculations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/relation') diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb index 0fa5ba2e50..3ef6e7928f 100644 --- a/activerecord/lib/active_record/relation/calculations.rb +++ b/activerecord/lib/active_record/relation/calculations.rb @@ -245,7 +245,7 @@ module ActiveRecord if distinct && (group_values.any? || select_values.empty? && order_values.empty?) column_name = primary_key end - elsif /\s*DISTINCT[\s(]+/i.match?(column_name.to_s) + elsif column_name.is_a?(::String) && /\bDISTINCT[\s(]/i.match?(column_name) distinct = nil end end -- cgit v1.2.3