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

zeitwerk-2.1.9, ruby-2.5.5, Rails 6.0 upgrade uninitialized constant ApplicationJob (NameError) #76

Closed
fredv opened this issue Aug 28, 2019 · 2 comments

Comments

@fredv
Copy link

fredv commented Aug 28, 2019

First of all, thank you so much for tackling autoloading.

When upgrading a large Rails 5.2 app, I'm encountering the following:

.rbenv/versions/2.5.5/lib/ruby/gems/2.5.0/gems/zeitwerk-2.1.9/lib/zeitwerk/loader.rb:351:in const_get': uninitialized constant ApplicationJob (NameError) Did you mean? ApplicationJob

After enabling the log, it happens when zeitwerk starts loading the jobs folder in the Rails app.
The folder contains a file "application_job.rb" with the following content:
class ApplicationJob < ActiveJob::Base queue_as :default end

As this is a quite common pattern, I wonder what the correct way of declaration and usage of such Base Wrapper classes is in order for the autoloading to pick up on it. I also wonder, why the class name is picked up by the typo suggestion below the error output but not Zeitwerk.

Is this a matter of load order, do extensions of Rails Base classes need to be placed in a different namespace or loaded before-hand?

@byroot
Copy link
Contributor

byroot commented Aug 29, 2019

No, it should definitely work, there must be something else that cause this exception.

Could you shared more details? e.g. the last few lines of the zeitwerk logs, and potentially try to repro in a new app.

@fredv
Copy link
Author

fredv commented Aug 29, 2019

@byroot thank you for your reply! In a newly created rails 6 app it works fine. I resolved the issue as it was caused by ApplicationJob being referenced in an initializer by moving the code to config.after_initialize.

@fredv fredv closed this as completed Aug 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants