aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/railtie.rb
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2017-05-28 10:47:17 +0200
committerKasper Timm Hansen <kaspth@gmail.com>2017-05-28 10:47:17 +0200
commit85211ea1efd5c249ef53182a0e5e09a56d6f9dd8 (patch)
treebb0b30de170b318a18c765bf2048667a2beb32db /activesupport/lib/active_support/railtie.rb
parent96be81303e2f5d19c1246ca0fdc4d0029b0b4a8f (diff)
downloadrails-85211ea1efd5c249ef53182a0e5e09a56d6f9dd8.tar.gz
rails-85211ea1efd5c249ef53182a0e5e09a56d6f9dd8.tar.bz2
rails-85211ea1efd5c249ef53182a0e5e09a56d6f9dd8.zip
Clear all current instances before a reload.
If users added an attribute or otherwise changed a CurrentAttributes subclass they'd see exceptions on the next page load. Because `ActiveSupport::CurrentAttributes.current_instances` would keep references to the old instances from the previous request. We can fix this by clearing out the `current_attributes` before we unload constants. Then any change to the model can be autoloaded again since its slot isn't taken by an old instance. We'll still have to call reset before we clear so external collaborators, like Time.zone, won't linger with their current value throughout other code.
Diffstat (limited to 'activesupport/lib/active_support/railtie.rb')
-rw-r--r--activesupport/lib/active_support/railtie.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/railtie.rb b/activesupport/lib/active_support/railtie.rb
index 39c83f65a3..1b4ecf4d72 100644
--- a/activesupport/lib/active_support/railtie.rb
+++ b/activesupport/lib/active_support/railtie.rb
@@ -8,8 +8,9 @@ module ActiveSupport
config.eager_load_namespaces << ActiveSupport
initializer "active_support.reset_all_current_attributes_instances" do |app|
- app.executor.to_run { ActiveSupport::CurrentAttributes.reset_all }
- app.executor.to_complete { ActiveSupport::CurrentAttributes.reset_all }
+ app.reloader.before_class_unload { ActiveSupport::CurrentAttributes.clear_all }
+ app.executor.to_run { ActiveSupport::CurrentAttributes.reset_all }
+ app.executor.to_complete { ActiveSupport::CurrentAttributes.reset_all }
end
initializer "active_support.deprecation_behavior" do |app|