Skip to content

Commit 58dc080

Browse files
committed
Don't dup query values if they're frozen
We shouldn't dup query values if those values are frozen. For example if you have a script like: ```ruby class Post < ActiveRecord::Base default_scope { where(author: "foo", title: "bar") } end ``` The "foo" and "bar" strings would get dup'd even if you have frozen_string_literals set. I think this impacts all `where` calls, not just default_scope, and I think frozen string literals are more common so this should help more than just default_scope
1 parent fa9cf26 commit 58dc080

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

activerecord/lib/active_record/relation/query_attribute.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ def initialize(...)
1515
elsif @type.serialized?
1616
value_for_database
1717
elsif @type.mutable? # If the type is simply mutable, we deep_dup it.
18-
@value_before_type_cast = @value_before_type_cast.deep_dup
18+
unless @value_before_type_cast.frozen?
19+
@value_before_type_cast = @value_before_type_cast.deep_dup
20+
end
1921
end
2022
end
2123

0 commit comments

Comments
 (0)