Skip to content

Commit

Permalink
Only run load_subclasses after app is initialized
Browse files Browse the repository at this point in the history
In rails 6.1, nothing was calling descendants or subclasses during the
app initialization.

Rails changed in 7.0 to call subclasses from reload_schema_from_cache here:
rails/rails@6f30cc0

It also changed to call descendants on the callback class (self) insead of
the ActiveSupport::DescendantsTracker here:
rails/rails@ffae3bd

We are not expecting to be called from these locations.

We can make this rails 7 compatible by ensuring the descendant loader loading
of subclasses until after the app is booted, which was the implicit behavior
previously.
  • Loading branch information
jrafanie committed Feb 21, 2024
1 parent 0325637 commit 3447c7a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/extensions/descendant_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def scoped_name(name, scopes)

module ArDescendantsWithLoader
def descendants
unless defined? @loaded_descendants
if Vmdb::Application.instance.initialized? && !defined? @loaded_descendants
@loaded_descendants = true
DescendantLoader.instance.load_subclasses(self)
end
Expand All @@ -275,7 +275,7 @@ def descendants
# https://github.com/rails/rails/commit/8f8aa857e084b76b1120edaa9bb9ce03ba1e6a19
# We need to get in front of it, like we do for descendants.
def subclasses
unless defined? @loaded_descendants
if Vmdb::Application.instance.initialized? && !defined? @loaded_descendants
@loaded_descendants = true
DescendantLoader.instance.load_subclasses(self)
end
Expand Down

0 comments on commit 3447c7a

Please sign in to comment.