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

Class loader Issue MaintenanceTasks::CsvCollectionBuilder #642

Closed
orbanbotond opened this issue May 31, 2022 · 4 comments
Closed

Class loader Issue MaintenanceTasks::CsvCollectionBuilder #642

orbanbotond opened this issue May 31, 2022 · 4 comments
Labels

Comments

@orbanbotond
Copy link

orbanbotond commented May 31, 2022

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]
@etiennebarrie
Copy link
Member

Yeah we've noticed in #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.

@drcapulet
Copy link
Contributor

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

@akabiru
Copy link

akabiru commented Nov 4, 2022

Cheers @drcapulet. For anyone curious about the zeitwerk inflections mentioned in #642 (comment)

Copy link

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!

@github-actions github-actions bot added the stale label Jan 26, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants