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

[WIP] Rails7 #22873

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

[WIP] Rails7 #22873

wants to merge 15 commits into from

Conversation

jrafanie
Copy link
Member

@jrafanie jrafanie commented Feb 1, 2024

Part of #22052

@jrafanie
Copy link
Member Author

miq-bot pushed a commit to ManageIQ/manageiq-cross_repo-tests that referenced this pull request May 14, 2024
@jrafanie jrafanie force-pushed the rails7 branch 2 times, most recently from 773fd54 to fe1d769 Compare May 20, 2024 18:26
@jrafanie
Copy link
Member Author

jrafanie commented Jun 3, 2024

@miq-bot cross-repo-tests /all #22873 ManageIQ/manageiq-ui-classic#9119

Rails 7 autoloading during boot doesn't use autoload_paths
so you must use either to_prepare hooks, after_initialize, on_load
hooks for frameworks, or by avoiding autoload entirely by manually
requiring files needed to be loaded during rails boot.

See also: https://guides.rubyonrails.org/v7.0/autoloading_and_reloading_constants.html#autoloading-when-the-application-boots

"While booting, applications can autoload from the autoload once paths, which are managed by the once autoloader. Please check the section config.autoload_once_paths above.
However, you cannot autoload from the autoload paths, which are managed by the main autoloader. This applies to code in config/initializers as well as application or engines initializers.
Why? Initializers only run once, when the application boots. If you reboot the server, they run again in a new process, but reloading does not reboot the server, and initializers don't run again."
See rails commit: e3b9779cb701c63012bc1af007c71dc5a888d35a

Very similar to the change found in:
https://github.com/ManageIQ/activerecord-virtual_attributes/pull/133/files
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)
Fixes the warning:

DEPRECATION WARNING: ActiveSupport::TimeWithZone.name has been deprecated and
from Rails 7.1 will use the default Ruby implementation.
You can set `config.active_support.remove_deprecated_time_with_zone_name = true`
to enable the new behavior now.
 (called from block in ruby_object_usage at /Users/joerafaniello/Code/manageiq/app/models/miq_worker/runner.rb:435)
We were using a private class variable.  There's a public interface we can use
and avoid a deprecation by switching from the variable to subclasses:

ActiveSupport::DescendantsTracker.direct_descendants is deprecated and will be removed in Rails 7.1.
Use ActiveSupport::DescendantsTracker.subclasses instead.
We're now eager loading subclasses when loading the parent but this is far
less reliant on hacks and closer to full eager loading, which is what rails has
been pushing us to do for years.  Let's try it out.

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.

Avoiding descendants / subclasses calls in conditionals like this are just brittle
so we need to stop hooking through these methods:
if !%w[reload_schema_from_cache __update_callbacks descendants subclasses].include?(caller_locations.first.base_label)
This is an attempt to reimplement ManageIQ#22853 since that was
reverted in ManageIQ#23038.
miq-bot pushed a commit to ManageIQ/manageiq-cross_repo-tests that referenced this pull request Jun 3, 2024
@miq-bot
Copy link
Member

miq-bot commented Jun 3, 2024

Checked commits jrafanie/manageiq@282c24f~...27119be with ruby 2.7.8, rubocop 1.56.3, haml-lint 0.51.0, and yamllint
23 files checked, 15 offenses detected

app/models/vm_reconfigure_task.rb

lib/extensions/descendant_loader.rb

  • ❗ - Line 266, Col 120 - Performance/Caller - Use caller_locations(1..1).first instead of caller_locations.first.
  • ❗ - Line 266, Col 87 - Rails/NegateInclude - Use .exclude? and remove the negation part.
  • ❗ - Line 278, Col 149 - Performance/Caller - Use caller_locations(1..1).first instead of caller_locations.first.
  • ❗ - Line 278, Col 87 - Rails/NegateInclude - Use .exclude? and remove the negation part.

lib/manageiq/session.rb

lib/miq_preloader.rb

spec/lib/extensions/ar_to_model_hash_spec.rb

spec/models/vm_reconfigure_task_spec.rb

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.

None yet

2 participants