Skip to content

Eagerly load Gitlab::I18n in config initializer

Peter Leitzen requested to merge pl-gitlab-i18n-deprecation-warning into master

What does this MR do and why?

Refs !111983 (merged)

This avoids the following warning:

DEPRECATION WARNING: Initialization autoloaded the constant Gitlab::I18n.

Being able to do this is deprecated. Autoloading during initialization is going
to be an error condition in future versions of Rails.

Reloading does not reboot the application, and therefore code executed during
initialization does not run again. So, if you reload Gitlab::I18n, for example,
the expected changes won't be reflected in that stale Module object.

This autoloaded constant has been unloaded.

In order to autoload safely at boot time, please wrap your code in a reloader
callback this way:

    Rails.application.reloader.to_prepare do
      # Autoload classes and modules needed at boot time here.
    end

That block runs when the application boots, and every time there is a reload.
For historical reasons, it may run twice, so it has to be idempotent.

Check the "Autoloading and Reloading Constants" guide to learn more about how
Rails autoloads and reloads.

How to verify locally

bin/rspec spec/lib/gitlab/i18n_spec.rb

On master you'll see the warning. It's gone on this branch.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Peter Leitzen

Merge request reports