Rails 5 RuntimeError: can't modify frozen Hash
stevenspiel opened this issue · 11 comments
I just upgraded to Rails 5 and I'm getting an error that stems from this line:
options = env[ENV_SESSION_OPTIONS]
options[:renew] = true if options
env[ENV_SESSION_OPTIONS]
is a frozen hash, and so it cannot be modified.
Using version 1.2.7
with Rails 5.0.0
and Ruby 2.3.1
Changing rack version from 2.0.2
to 2.0.1
fixed it. But there must be some other solution.
I have the same problem and @stevenspiel's solution worked. But this is not a proper solution.
See rack/rack#1110 for the change that freezes the DEFAULT_OPTIONS
hash in Rack.
See rails/rails#26442 for the Rails 5.1 fix that avoids assigning DEFAULT_OPTIONS
to request.session_options
in ActionController::TestSession
. The fix has been backported to the Rails 5.0 branch, but it has not been included in a 5.0 release.
@whithub I believe it's still an issue.
I think the fix for warden
is to do something like this:
diff --git a/lib/warden/proxy.rb b/lib/warden/proxy.rb
index b6cc857..86697df 100644
--- a/lib/warden/proxy.rb
+++ b/lib/warden/proxy.rb
@@ -172,7 +172,7 @@ module Warden
if opts[:store] != false && opts[:event] != :fetch
options = env[ENV_SESSION_OPTIONS]
- options[:renew] = true if options
+ env[ENV_SESSION_OPTIONS] = options.merge(renew: true) if options
session_serializer.store(user, scope)
end
Could this fix be merged? I'm having this issue. =(
@HeidiHansen There isn't a PR. I haven't actually tested my proposed fix since I haven't encountered this problem recently.
Looking at that patch again, it should probably check if the original options are frozen?
and re-freeze the merged Hash
.
Yeah we could use a hand creating a test case to re-produce the issue. It is proving more time consuming than we'd anticipated. @HeidiHansen @md5 if you guys have the time to get a failure for us to work with.
Still facing the same issue when trying to migrate/initialise database.
FrozenError: can't modify frozen Hash /usr/share/rvm/gems/ruby-2.5.3/gems/activesupport-5.2.4.6/lib/active_support/deprecation/method_wrappers.rb:54:in
delete'
`
On rails 5.2.4.3
Getting the following
- export RAILS_ENV=development
- RAILS_ENV=development
- rails db:environment:set RAILS_ENV=development
rails aborted!
FrozenError: can't modify frozen Hash
/usr/share/rvm/gems/ruby-2.5.3/gems/activesupport-5.2.4.6/lib/active_support/deprecation/method_wrappers.rb:54:indelete' /usr/share/rvm/gems/ruby-2.5.3/gems/activesupport-5.2.4.6/lib/active_support/deprecation/method_wrappers.rb:54:in
deprecate_methods'
/usr/share/rvm/gems/ruby-2.5.3/gems/rswag-api-2.13.0/lib/rswag/api.rb:32:in<module:Api>' /usr/share/rvm/gems/ruby-2.5.3/gems/rswag-api-2.13.0/lib/rswag/api.rb:6:in
module:Rswag'
/usr/share/rvm/gems/ruby-2.5.3/gems/rswag-api-2.13.0/lib/rswag/api.rb:5:in<top (required)>' /usr/share/rvm/gems/ruby-2.5.3/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in
require'
/usr/share/rvm/gems/ruby-2.5.3/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:inrequire' /var/www/project_path/config/application.rb:18:in
<top (required)>'
/var/www/project_path/Rakefile:4:inrequire_relative' /var/www/project_path/Rakefile:4:in
<top (required)>'
/usr/share/rvm/gems/ruby-2.5.3/gems/railties-5.2.4.6/lib/rails/commands/rake/rake_command.rb:22:inblock in perform' /usr/share/rvm/gems/ruby-2.5.3/gems/railties-5.2.4.6/lib/rails/commands/rake/rake_command.rb:20:in
perform'
/usr/share/rvm/gems/ruby-2.5.3/gems/railties-5.2.4.6/lib/rails/command.rb:48:ininvoke' /usr/share/rvm/gems/ruby-2.5.3/gems/railties-5.2.4.6/lib/rails/commands.rb:18:in
<top (required)>'
/usr/share/rvm/gems/ruby-2.5.3/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:inrequire' /usr/share/rvm/gems/ruby-2.5.3/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in
require'
/var/www/project_path/bin/rails:9:in<top (required)>' /usr/share/rvm/gems/ruby-2.5.3/gems/spring-2.1.1/lib/spring/client/rails.rb:28:in
load'
/usr/share/rvm/gems/ruby-2.5.3/gems/spring-2.1.1/lib/spring/client/rails.rb:28:incall' /usr/share/rvm/gems/ruby-2.5.3/gems/spring-2.1.1/lib/spring/client/command.rb:7:in
call'
/usr/share/rvm/gems/ruby-2.5.3/gems/spring-2.1.1/lib/spring/client.rb:30:inrun' /usr/share/rvm/gems/ruby-2.5.3/gems/spring-2.1.1/bin/spring:49:in
<top (required)>'
/usr/share/rvm/gems/ruby-2.5.3/gems/spring-2.1.1/lib/spring/binstub.rb:11:inload' /usr/share/rvm/gems/ruby-2.5.3/gems/spring-2.1.1/lib/spring/binstub.rb:11:in
<top (required)>'
/var/www/project_path/bin/spring:15:inrequire' /var/www/project_path/bin/spring:15:in
<top (required)>'
bin/rails:3:inload' bin/rails:3:in
'
Caused by:
LoadError: cannot load such file -- rswag-api