Skip to content
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

Merged
merged 5 commits into from
Aug 6, 2024
Merged

Rails 7 #22873

merged 5 commits into from
Aug 6, 2024

Conversation

jrafanie
Copy link
Member

@jrafanie jrafanie commented Feb 1, 2024


def excluded_parent?(parent)
EXCLUDED_PARENTS.include?(parent.to_s)
end
Copy link
Member Author

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.

Copy link
Member Author

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.

@jrafanie jrafanie force-pushed the rails7 branch 5 times, most recently from c17092f to 0fda41e Compare July 31, 2024 21:14

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
Copy link
Member

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?

Suggested change
# 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

Copy link
Member

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 ?

Copy link
Member Author

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.


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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too

Suggested change
# 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"
Copy link
Member Author

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

@jrafanie jrafanie changed the title [WIP] Rails7 Rails 7 Aug 2, 2024
@jrafanie jrafanie removed the wip label Aug 2, 2024
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)
Copy link
Member Author

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.

@miq-bot
Copy link
Member

miq-bot commented Aug 6, 2024

Checked commits jrafanie/manageiq@3b74f5a~...b85a0c7 with ruby 3.1.5, rubocop 1.56.3, haml-lint 0.51.0, and yamllint
10 files checked, 2 offenses detected

app/models/vm_reconfigure_task.rb

spec/models/vm_reconfigure_task_spec.rb

@Fryguy Fryguy self-assigned this Aug 6, 2024
Copy link
Member

@GilbertCherrie GilbertCherrie left a 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.

@Fryguy Fryguy merged commit 6f8fdeb into ManageIQ:master Aug 6, 2024
8 checks passed
@jrafanie jrafanie deleted the rails7 branch August 9, 2024 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants