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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Kris-37
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.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/84774599-ef39-4080-8861-7571f791591a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

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

On Friday, 10 November 2017 10:26:31 UTC, Kris wrote:
key = 'foo'

key.frozen? # => false

TextFieldDefinition.create(key: key)

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


I created a <a href="https://gist.github.com/krisleech/017946a8c928c3f16ce1e54de09aab83#file-02_test-rb" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fkrisleech%2F017946a8c928c3f16ce1e54de09aab83%23file-02_test-rb\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGLDrN69mYYMcBbYkPRlWYgZ71Vwg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fkrisleech%2F017946a8c928c3f16ce1e54de09aab83%23file-02_test-rb\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGLDrN69mYYMcBbYkPRlWYgZ71Vwg&#39;;return true;">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.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/39dd4c57-37af-4cbd-afcb-ab3dac962b14%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.