ActiveRecord/ActiveModel freezes attribute values in Rails 5 (possible bug)

key = 'foo'

key.frozen? # => false

TextFieldDefinition.create(key: key)

key.frozen? # => true (not expected)

I created a minimal example to demonstrate the bug this but it does not reproduce it.

It appears that in my production code ActiveModel::Type::ImmutableString#cast_type, which freezes the value, is called, but isn’t in my attempt at a reproduction of the bug.

Any ideas?

I’m assuming Rails shouldn’t modify input’s in any way and should #dup them first.

Many thanks.

Looks like this was a bug and is fixed: https://github.com/rails/rails/commit/8de7df5b22e853f028e5a71b26d45a0ce7a2c0f4#diff-da764be48e98c7b140730924b50595b0