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

Classic autoloader support #528

Closed
gmcgibbon opened this issue Nov 15, 2021 · 5 comments · Fixed by #529 or #620
Closed

Classic autoloader support #528

gmcgibbon opened this issue Nov 15, 2021 · 5 comments · Fixed by #529 or #620
Assignees
Labels
bug Something isn't working
Milestone

Comments

@gmcgibbon
Copy link
Member

Classic autoload reloading seems to be broken in the dummy app (and apps that use the classic autoloader). You can reproduce the error with the following:

  • cd test/dummy
  • CLASSIC_AUTOLOADER=1 bin/rails c
  • reload!
Reloading...
~/src/github.com/Shopify/maintenance_tasks/app/models/maintenance_tasks/task.rb:62:in `csv_collection': uninitialized constant CsvCollectionBuilder (NameError)

Adding a require_dependency to app/models/maintenance_tasks/task.rb fixes the problem, but our support for non-Zeitwerk applications is unclear. Should we support them, or not? If not, I suggest we remove the ENV var to boot in classic mode. Also, keep in mind Rails 7 will not include the classic autoloader as Zeitwerk has been the default for quite awhile now.

@gmcgibbon gmcgibbon added the bug Something isn't working label Nov 15, 2021
@adrianna-chang-shopify
Copy link
Contributor

our support for non-Zeitwerk applications is unclear

We currently ensure that we're compatible with the classic autoloader by eager loading the app and requiring all task files in the engine:

initializer "eager_load_for_classic_autoloader" do
eager_load! unless Rails.autoloaders.zeitwerk_enabled?
end

unless Rails.autoloaders.zeitwerk_enabled?
tasks_module = MaintenanceTasks.tasks_module.underscore
Dir["#{Rails.root}/app/tasks/#{tasks_module}/*.rb"].each do |file|
require_dependency(file)
end
end

So I'd say that we have tried to support it up until this point 😄 That said, I'm not sure it's worth doing. As you said, Zeitwerk is the default in Rails 6 apps, and classic autoloading won't be supported soon, so I think it's fair game to enforce Zeitwerk. It also lets us get rid of the above code. I'd be OK to disable classic mode and call it out in the docs.

@etiennebarrie
Copy link
Member

I think it was just a matter of qualifying CsvCollectionBuilder (=> MaintenanceTasks::CsvCollectionBuilder).

I couldn't write a test to cause the exception though (using Rails.application.reloader.reload! or even including the Rails::ConsoleMethods and calling reload! wasn't working from a rake task for some reason).

I'm conflicted because this particular means of testing autoloading has been failing forever basically (since v1.1.1), but in general autoloading from the UI works, and you can run your task. I mean it's pretty bad that we broke reload!, but you could run your tasks with the classic autoloader, now the UI is entirely broken.
On the other hand, migrating to Zeitwerk doesn't seem too hard on users, and we can avoid having to support it…

I don't know I just feel bad dropping support abruptly. I guess we'll see if we get some bug reports whenever this is released.

@gmcgibbon
Copy link
Member Author

I'm happy to revert and log a deprecation instead in the next release, if we think it is necessary.

@adrianna-chang-shopify
Copy link
Contributor

On the other hand, migrating to Zeitwerk doesn't seem too hard on users, and we can avoid having to support it…

My feeling was that we'd been supporting classic autoloading in a half-broken manner up until recently with no complaints, and support for non-Zeitwerk apps is going to be dropped soon with Rails 7, so apps should be focused on migrating anyways.

I agree that dropping it with no notice is probably bad OSS etiquette though 😅

So maybe we should revert, qualify the constant to fix reloading, and soft deprecate for now?

@gmcgibbon
Copy link
Member Author

Ok, I'll revert and warn instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants