-
Notifications
You must be signed in to change notification settings - Fork 898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change DescendantLoader to handle non-AR classes in the models directory #16867
Change DescendantLoader to handle non-AR classes in the models directory #16867
Conversation
Class is patched by ActiveSupport to add the descendants method, so this change keeps our patching of ActiveSupport consistent across the board by also patching Class. This was handled specifically for ActsAsArModel previously, but there are other classes that also might need this functionality such as Authenticator. Individually adding new classes is not maintainable and also not expected, so this is handled generically via a patch to Class. We still need to keep our ActiveRecord::Base patch because due to timing. By the time we hit the patching lines, ActiveRecord::Base has already been further modified with ActiveSupport::DescendantsTracker via prepend, and if we were to rely on the Class patch, then we wouldn't be able to get ahead of DescendantsTracker. Visually, the singleton_class' ancestors chain looks like this for Object: [ #<Class:Object>, ... DescendantLoader::ArDescendantsWithLoader, Class, ... Object, ... ] but looks like this for ActiveRecord::Base (if we were to rely on the Class patch only): [ #<Class:ActiveRecord::Base>, ... ActiveSupport::DescendantsTracker, ... #<Class:Object>, ... DescendantLoader::ArDescendantsWithLoader, Class, ... Object, ... ] Thus ActiveSupport::DescendantsTracker's definition of descedants wins, unless we patch ActiveRecord::Base directly. https://bugzilla.redhat.com/show_bug.cgi?id=1537299
Note that this just changes the DescendantLoader...there is a follow up PR incoming to change |
Checked commit Fryguy@104416d with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 LGTM
👍 LGTM Thank you @Fryguy |
I dislike autoload and the hackery we need to do 😢 . With that said, this looks like a much better solution than handling non-model classes one at a time. |
After ManageIQ#16867, the DescendantLoader now works properly with non-AR models such as the Authenticator. Much of the code in the Authenticator, such as require_nested and force_load_authenticator_for is just workarounds over the issues from DescendantLoader, so these can be removed. Additionally, the only caller of the authenticator_class was the validator, so this commit moves the validation code into the Authenticator class directly, allow us to make all of those authenticator_class methods private. Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1537299
After ManageIQ#16867, the DescendantLoader now works properly with non-AR models such as the Authenticator. Much of the code in the Authenticator, such as require_nested and force_load_authenticator_for is just workarounds over the issues from DescendantLoader, so these can be removed. Additionally, the only caller of the authenticator_class was the validator, so this commit moves the validation code into the Authenticator class directly, allow us to make all of those authenticator_class methods private. Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1537299
After ManageIQ#16867, the DescendantLoader now works properly with non-AR models such as the Authenticator. Much of the code in the Authenticator, such as require_nested and force_load_authenticator_for is just workarounds over the issues from DescendantLoader, so these can be removed. Additionally, the only caller of the authenticator_class was the validator, so this commit moves the validation code into the Authenticator class directly, allow us to make all of those authenticator_class methods private. Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1537299
…r_models Change DescendantLoader to handle non-AR classes in the models directory (cherry picked from commit d4ce76f) https://bugzilla.redhat.com/show_bug.cgi?id=1537788
Gaprindashvili backport details:
|
Class is patched by ActiveSupport to add the descendants method, so this change
keeps our patching of ActiveSupport consistent across the board by also patching
Class. This was handled specifically for ActsAsArModel previously, but there
are other classes that also might need this functionality such as Authenticator.
Individually adding new classes is not maintainable and also not expected, so
this is handled generically via a patch to Class.
We still need to keep our ActiveRecord::Base patch because due to timing. By
the time we hit the patching lines, ActiveRecord::Base has already been further
modified with ActiveSupport::DescendantsTracker via prepend, and if we were to
rely on the Class patch, then we wouldn't be able to get ahead of
DescendantsTracker.
Visually, the singleton_class' ancestors chain looks like this for Object:
but looks like this for ActiveRecord::Base (if we were to rely on the
Class patch only):
Thus ActiveSupport::DescendantsTracker's definition of descedants wins, unless
we patch ActiveRecord::Base directly.
https://bugzilla.redhat.com/show_bug.cgi?id=1537299
Paired on this with @jvlcek and @bdunne
@jrafanie Please review.