Initialization autoloaded the constants x, y, and z. Isn't enough information

Hello @andy_nutter-upham.

Let me clarify first that this deprecation is unrelated to Zeitwerk.

Rails has an autoload logic, and it defers the technical details of how to autoload, how to reload, etc. to its autoloaders. Before Rails 6, and going back to 2004, there was only one choice. Nowadays you have two.

When things reload, how does the application boot and sets things up, how do you lock to make reloading thread-safe, etc. That is Rails-specific logic. For example, other web frameworks autoloading with Zeitwerk have their own logic.

I am not saying you had to know this, of course, just explaining it so that you can build a mental model.

OK, so you’ll get this warning because Rails issues it, and that happens in both autoloading modes. It is a new warning of Rails 6.

Once that precision has been made, unfortunately none of the autoloaders have information about where was the constant lookup triggered. Ruby does not give you that information. You know in which file is the constant defined, but not which reference to the constant caused the lookup.

However, since that happened in the initializers, the scope is reduced. Your first option is to grep them:

ag Foo config/initializers

If, for some reason that is not helpful, you can always go to the file foo.rb and put at the top

pp caller_locations

This last technique works in any scenario.

5 Likes