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

Rails7 friendly require during initializers #23102

Merged

Conversation

jrafanie
Copy link
Member

@jrafanie jrafanie commented Jul 22, 2024

Extracted from: #22873

These changes should be backward compatible with rails 6.1 and allows us to be rails 7 friendly by not trying to autoload during application initialization.

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."

@jrafanie jrafanie requested a review from Fryguy as a code owner July 22, 2024 19:44
@jrafanie
Copy link
Member Author

@miq-bot cross-repo-tests /all

@jrafanie jrafanie mentioned this pull request Jul 22, 2024
miq-bot pushed a commit to ManageIQ/manageiq-cross_repo-tests that referenced this pull request Jul 22, 2024
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."
@jrafanie jrafanie force-pushed the rails7_friendly_require_during_initializers branch from 61be0d0 to 814bb44 Compare July 22, 2024 21:24
@miq-bot
Copy link
Member

miq-bot commented Jul 22, 2024

Checked commits jrafanie/manageiq@25567c9~...814bb44 with ruby 3.1.5, rubocop 1.56.3, haml-lint 0.51.0, and yamllint
10 files checked, 0 offenses detected
Everything looks fine. 🏆

@Fryguy Fryguy merged commit 4260052 into ManageIQ:master Jul 22, 2024
8 checks passed
@jrafanie jrafanie deleted the rails7_friendly_require_during_initializers branch September 5, 2024 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants