-
Notifications
You must be signed in to change notification settings - Fork 900
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
Rails 7 #22873
Rails 7 #22873
Conversation
a495d2d
to
59d87c0
Compare
322ef1c
to
803369e
Compare
lib/extensions/descendant_loader.rb
Outdated
|
||
def excluded_parent?(parent) | ||
EXCLUDED_PARENTS.include?(parent.to_s) | ||
end |
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.
Ok, I've split this excluded parents concept into it's own commit. We can choose to drop it as it's only an optimization. We can followup with it if it's questionable.
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.
This isn't needed. @kbrock helped me find out that if the __update_callbacks
entrypoint for descendants
is excluded, there is no time that we are calling descendants
on these high level classes. Dropping this commit.
c17092f
to
0fda41e
Compare
spec/lib/miq_preloader_spec.rb
Outdated
|
||
expect { preload(emses, :vms, vms) }.not_to make_database_queries | ||
expect { expect(emses.first.vms.size).to eq(2) }.not_to make_database_queries | ||
expect { expect(vms.first.ext_management_system).to eq(ems) }.not_to make_database_queries | ||
|
||
# This PR seems to indicate only the singular associations are preloaded after the rails 7 refactor |
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.
Very minor, but can you mark this with a TODO tag?
# This PR seems to indicate only the singular associations are preloaded after the rails 7 refactor | |
# TODO: This PR seems to indicate only the singular associations are preloaded after the rails 7 refactor |
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.
Perhaps the other Rails 7 things with the database query counts should also be marked as TODO ?
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.
Thanks, that's a good idea. Keenan and I were discussing it yesterday and they're the only thing we've left to look at in this PR. We're trying a quick dive into them to see if we can determine why they need to change and we'll either mark them TODO as you suggest, pending (for failed assertions that we previously thought should still work... see line 81 below), or some combination.
spec/lib/miq_preloader_spec.rb
Outdated
|
||
expect { preload(emses, :vms, vms) }.not_to make_database_queries | ||
expect { expect(emses.first.vms.size).to eq(2) }.not_to make_database_queries | ||
expect { expect(vms.first.ext_management_system).to eq(ems) }.not_to make_database_queries | ||
|
||
# This PR seems to indicate only the singular associations are preloaded after the rails 7 refactor |
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.
Here too
# This PR seems to indicate only the singular associations are preloaded after the rails 7 refactor | |
# TODO: This PR seems to indicate only the singular associations are preloaded after the rails 7 refactor |
@@ -69,8 +69,8 @@ gem "psych", ">=3.1", :require => false # | |||
gem "query_relation", "~>0.1.0", :require => false | |||
gem "rack", ">=2.2.6.4", :require => false | |||
gem "rack-attack", "~>6.5.0", :require => false | |||
gem "rails", "~>6.1.7", ">=6.1.7.8" | |||
gem "rails-i18n", "~>6.x" | |||
gem "rails", "~>7.0.8", ">=7.0.8.4" |
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.
Just pushed this change to set minimum to ensure latest CVE coverage
Require minimum for the CVE fixes: https://rubyonrails.org/2024/6/4/Rails-Versions-6-1-7-8-7-0-8-4-and-7-1-3-4-have-been-released Use virtual attributes 7.0 and other gems that support rails 7.
See rails commit: e3b9779cb701c63012bc1af007c71dc5a888d35a Very similar to the change found in: https://github.com/ManageIQ/activerecord-virtual_attributes/pull/133/files Stub/mock the preloader in a rails 7 compatible way Rails 7 preloader requires a scope relation, not an array Note, it looks like only singular associations for already available_records are preloaded with an optimization in rails 7. See: https://www.github.com/rails/rails/pull/42654
Fixes the following deprecation warnings: DEPRECATION WARNING: Time#to_s(:db) is deprecated. Please use Time#to_fs(:db) instead. (called from block (2 levels) in add_metric_rollups_for at /Users/joerafaniello/Code/manageiq/spec/support/chargeback_helper.rb:43) DEPRECATION WARNING: Integer#to_s(:human_size) is deprecated. Please use Integer#to_fs(:human_size) instead. (called from block in build_disk_message at /Users/joerafaniello/Code/manageiq/app/models/vm_reconfigure_task.rb:43) DEPRECATION WARNING: Integer#to_s(:human_size) is deprecated. Please use Integer#to_fs(:human_size) instead. (called from block (3 levels) in <main> at /Users/joerafaniello/Code/manageiq/spec/models/vm_reconfigure_task_spec.rb:45) DEPRECATION WARNING: Integer#to_s(:human_size) is deprecated. Please use Integer#to_fs(:human_size) instead. (called from block (3 levels) in <main> at /Users/joerafaniello/Code/manageiq/spec/models/vm_reconfigure_task_spec.rb:58) DEPRECATION WARNING: Integer#to_s(:human_size) is deprecated. Please use Integer#to_fs(:human_size) instead. (called from block (3 levels) in <main> at /Users/joerafaniello/Code/manageiq/spec/models/vm_reconfigure_task_spec.rb:59)
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're now getting called in descendants and subclasses from rails very early, at code load time, before models or as models are in between loading. We cannot trigger loads of subclasses while we're loading the existing class so we must wait and avoid it at this point.
def descendants | ||
if Vmdb::Application.instance.initialized? && !defined? @loaded_descendants | ||
if Vmdb::Application.instance.initialized? && !defined?(@loaded_descendants) && %w[__update_callbacks].exclude?(caller_locations(1..1).first.base_label) |
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.
the bot/cop complained about using caller_locations to build the full array so I accepted that suggestion even though I think it makes it a bit more convoluted. This method can be run many times, especially when models aren't yet loaded, so it should be as performant as possible.
Checked commits jrafanie/manageiq@3b74f5a~...b85a0c7 with ruby 3.1.5, rubocop 1.56.3, haml-lint 0.51.0, and yamllint app/models/vm_reconfigure_task.rb
spec/models/vm_reconfigure_task_spec.rb
|
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.
Ui seems to be working correctly and updates are being loaded correctly as well.
Fixes the following error on rails 7.1: TypeError: no implicit conversion of Symbol into Integer Shared Example Group: "used" called from ./spec/content/automate/ManageIQ/System/CommonMethods/QuotaMethods.class/__methods__/used_spec.rb:59 ./content/automate/ManageIQ/System/CommonMethods/QuotaMethods.class/__methods__/used.rb:25:in `to_s' ./content/automate/ManageIQ/System/CommonMethods/QuotaMethods.class/__methods__/used.rb:25:in `used' ./content/automate/ManageIQ/System/CommonMethods/QuotaMethods.class/__methods__/used.rb:18:in `main' ./spec/content/automate/ManageIQ/System/CommonMethods/QuotaMethods.class/__methods__/used_spec.rb:41:in `block (3 levels) in <top (required)>' Fixes the following deprecation warnings that should have picked this up on rails 7: DEPRECATION WARNING: Time#to_s(:db) is deprecated. Please use Time#to_fs(:db) instead. DEPRECATION WARNING: Integer#to_s(:human_size) is deprecated. Please use Integer#to_fs(:human_size) instead. A similar change was fixed in here in commit: ManageIQ/manageiq@21bc1a9 Part of this PR for Rails 7: ManageIQ/manageiq#22873
Part of #22052
After merging this, please merge the following: