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

Autoloading controllers in extension lib stopped working #79

Closed
mamhoff opened this issue Jun 13, 2023 · 4 comments · Fixed by #80
Closed

Autoloading controllers in extension lib stopped working #79

mamhoff opened this issue Jun 13, 2023 · 4 comments · Fixed by #80
Assignees
Labels

Comments

@mamhoff
Copy link
Contributor

mamhoff commented Jun 13, 2023

(originally reported here, but moving it here, as it affects not only solidus_auth_devise, but also solidus_braintree.

I'm experiencing the following error in a brand new Solidus Sandbox: Currently (Solidus main as of solidusio/solidus@78d20c4, solidus_auth_devise version 2.5.8) the sandbox can't find the backend sessions controller. This is the error when you try:

Started GET "/admin/" for 127.0.0.1 at 2023-06-12 15:37:29 +0200
  ActiveRecord::SchemaMigration Pluck (0.1ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
Processing by Spree::Admin::RootController#index as HTML
Redirected to http://localhost:3000/admin/login
Completed 302 Found in 340ms (ActiveRecord: 0.8ms | Allocations: 530212)


Started GET "/admin/login" for 127.0.0.1 at 2023-06-12 15:37:29 +0200
  
ActionController::RoutingError (uninitialized constant Spree::Admin::UserSessionsController

      Object.const_get(camel_cased_word)
            ^^^^^^^^^^
Did you mean?  UserPasswordsController

            raise MissingController.new(error.message, error.name)
            ^^^^^):
  
bin/rails zeitwerk:check

results in

Hold on, I am eager loading the application.

WARNING: The following directories will only be checked if you configure
them to be eager loaded:

  /home/anselm/.gem/ruby/3.1.4/gems/solidus_paypal_commerce_platform-1.0.1/app/decorators/models
  /home/anselm/.gem/ruby/3.1.4/gems/solidus_auth_devise-2.5.8/lib/decorators/backend/controllers
  /home/anselm/.gem/ruby/3.1.4/gems/solidus_auth_devise-2.5.8/lib/controllers/backend/spree

You may verify them manually, or add them to config.eager_load_paths
in config/application.rb and run zeitwerk:check again.

Otherwise, all is good!

Solidus Version:

Solidus main as of solidusio/solidus@78d20c4

To Reproduce

The simplest check for this is just running the rails console and typing the name of the controller we need. If all is good, the REPL should return the constant, if something's off, we get an undefined constant error:

=> Spree::Admin::UsersController
irb(main):007:0> Spree::Admin::UserSessionsController
(irb):7:in `<main>': uninitialized constant Spree::Admin::UserSessionsController (NameError)
Did you mean?  Spree::Admin::UsersController

This behavior occurs not just with solidus_auth_devise, but with any gem that has the backend controllers in lib. One example is solidus_braintree, with its SolidusBraintree::ConfigurationsController:

irb(main):002:0> SolidusBraintree
=> SolidusBraintree
irb(main):003:0> SolidusBraintree::ConfigurationsController
(irb):3:in `<main>': uninitialized constant SolidusBraintree::ConfigurationsController (NameError)

Current behavior

irb(main):002:0> SolidusBraintree::ConfigurationsController
(irb):3:in `<main>': uninitialized constant SolidusBraintree::ConfigurationsController (NameError)

Expected behavior

irb(main):002:0> SolidusBraintree::ConfigurationsController
=> SolidusBraintree::ConfigurationsController

Desktop (please complete the following information):

  • OS: [e.g. iOS] Fedora Linux
  • Browser [e.g. chrome, safari] Firfox, but it doesn't really matter.
  • Version [e.g. 22]

Additional context

This stopped working with the following commit: 17e8718

@mamhoff mamhoff added the bug label Jun 13, 2023
@DanielePalombo
Copy link
Contributor

Thank you for reporting this issue. I made a change to the autoload path of solidus_support last week. Probably this is the cause of the issue. Let me try to reproduce it locally.

@elia
Copy link
Member

elia commented Jun 13, 2023

@DanielePalombo can you also try to add a regression test for both situations?

@elia
Copy link
Member

elia commented Jun 15, 2023

I just got the same issue, moving from config.autoload_paths += controllers_path.glob('*') to config.autoload_paths += [controllers_path] seems to work and be consistent with https://edgeguides.rubyonrails.org/classic_to_zeitwerk_howto.html#globs-in-config-autoload-paths

I'll prepare a PR to fix this 🙋‍♂️

@elia elia self-assigned this Jun 15, 2023
@mamhoff
Copy link
Contributor Author

mamhoff commented Jun 15, 2023

This seems to work in the situation described above (tested locally using bundle open).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants