diff --git a/config/application.rb b/config/application.rb index 7d217bab6b9..03624e8c859 100644 --- a/config/application.rb +++ b/config/application.rb @@ -33,6 +33,8 @@ module Vmdb class Application < Rails::Application + attr_accessor :reloading + # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. @@ -191,6 +193,12 @@ class Application < Rails::Application # Reload Settings to get values from db now that it's safe to autoload ::Settings.reload! Vmdb::Loggers.apply_config(::Settings.log) + + # The descendant_loader.rb hooks descendants and subclasses to do proper sti loading of + # subclasses and descendants. It should not be used when code reload is happening. + Vmdb::Application.reloading = false + Vmdb::Application.reloader.before_class_unload { Vmdb::Application.reloading = true } + Vmdb::Application.reloader.to_complete { Vmdb::Application.reloading = false } end console do diff --git a/lib/extensions/descendant_loader.rb b/lib/extensions/descendant_loader.rb index f5ee438ba90..ae97645c1ba 100644 --- a/lib/extensions/descendant_loader.rb +++ b/lib/extensions/descendant_loader.rb @@ -278,7 +278,7 @@ module ArDescendantsWithLoader # "xxx/manageiq/app/models/vm_or_template.rb:15:in `'", # "xxx/manageiq/app/models/vm_or_template.rb:6:in `
'", def descendants - if Vmdb::Application.instance.initialized? && !defined?(@loaded_descendants) && %w[__update_callbacks].exclude?(caller_locations(1..1).first.base_label) + if Vmdb::Application.instance.initialized? && !defined?(@loaded_descendants) && %w[__update_callbacks].exclude?(caller_locations(1..1).first.base_label) && !Vmdb::Application.reloading @loaded_descendants = true DescendantLoader.instance.load_subclasses(self) end @@ -327,7 +327,7 @@ def descendants # "xxx/gems/activesupport-7.0.8.4/lib/active_support/descendants_tracker.rb:89:in `descendants'", # ... def subclasses - if Vmdb::Application.instance.initialized? && !defined?(@loaded_descendants) && %w[descendants reload_schema_from_cache subclasses].exclude?(caller_locations(1..1).first.base_label) + if Vmdb::Application.instance.initialized? && !defined?(@loaded_descendants) && %w[descendants reload_schema_from_cache subclasses].exclude?(caller_locations(1..1).first.base_label) && !Vmdb::Application.reloading @loaded_descendants = true DescendantLoader.instance.load_subclasses(self) end