maintenance_tasks
maintenance_tasks copied to clipboard
Class loader Issue MaintenanceTasks::CsvCollectionBuilder
As I turn on the eager loader and start the rails console I receive this error:
be rails c 7s arm64 2.7.3p183
/Users/orbanbotond/.frum/versions/2.7.3/lib/ruby/gems/2.7.0/gems/maintenance_tasks-1.10.1/app/models/maintenance_tasks/batch_csv_collection_builder.rb:9:in `<module:MaintenanceTasks>': uninitialized constant MaintenanceTasks::CsvCollectionBuilder
Did you mean? MaintenanceTasks::NoCollectionBuilder
MaintenanceTasks::BatchCSVCollectionBuilder
MaintenanceTasks::CSVCollectionBuilder (NameError)
This is my ruby version:
ruby -v 7s arm64 2.7.3p183
ruby 2.7.3p183 (2021-04-05 revision 6847ee089d) [arm64-darwin20]
Yeah we've noticed in https://github.com/Shopify/maintenance_tasks/pull/620 and dropped support for it for v2.0.0.
I think you could work around that issue, but I can't reproduce it myself. I've created a rails 6.1.6 app, installed active storage, installed the gem, set config.autoloader = :classic
and in development set config.eager_load = true
, but when I start the console it doesn't raise the issue.
I've also tried adding an inflection in config/initializers/inflections.rb
:
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.acronym "CSV"
end
Can you give me repro steps? From there we should be able to require the file and avoid the eager-loading issue.
Here are some reproduction steps with rails 6.1.7, but under Zeitwerk:
rails new testapp --skip-webpack-install --skip-javascript
Flip config.eager_load
to true
in config/environments/development.rb
.
Then edit config/initializers/inflections.rb
to have:
ActiveSupport::Inflector.inflections do |inflect|
inflect.acronym 'CSV'
end
And finally add gem 'maintenance_tasks'
to Gemfile
.
When you try to launch a console, it'll crash.
This is due to the fact that Rails doesn't isolate inflections to the main application, thus requiring something like:
Rails.autoloaders.each do |autoloader|
autoloader.inflector.inflect(
'batch_csv_collection_builder' => 'BatchCsvCollectionBuilder',
'csv_collection_builder' => 'CsvCollectionBuilder',
)
end
Cheers @drcapulet. For anyone curious about the zeitwerk inflections mentioned in https://github.com/Shopify/maintenance_tasks/issues/642#issuecomment-1292393956
- 📖 Check out https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#customizing-inflections
- Add
bin/rails zeitwerk:check
to your CI build, this will catch any autoload errors that would otherwise show up ineager_load
https://guides.rubyonrails.org/autoloading_and_reloading_constants.html#manual-testing
This issue has been marked as stale because it has not been commented on in two months. Please reply in order to keep the issue open. Otherwise, it will close in 14 days. Thank you for contributing!