On Tuesday, November 27, 2012 5:32:05 PM UTC-8, Leonardo de la Cerda Guzman wrote: > > Hello, > > I'm creating a model through Model::create, who is expecting a hash (value > parameter). > One hash value is a frozen string, and I receive an exception that some > code is trying to modify a frozen string. > > Of course, I can dup my parameter and it fixes everything. > But the natural thing is that the create function does not try to modify > my parameters. > > > I searched in the gem code and I found that in line 66 of > > lib/sequel/plugins/force_encoding.rb > def typecast_value(column, value) > s = super > s.force_encoding(model.forced_encoding) if s.is_a?(String) && > model.forced_encoding > s > > end > > the code is trying to force an encoding for that value parameter. This > happens in ruby 1.9 with the introduction of the string encoding handling. > > > I think a single s = s.dup would fix the issue. >
The force_encoding plugin is optional, so you shouldn't be using it unless you need it. Doing "s = s.dup" unconditionally is bad for performance. I guess the best way to handle this is to do "s = s.dup if s.frozen?" before the force_encoding call. I'll add that tomorrow. Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/sequel-talk/-/eSHEd-KhqSUJ. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
