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

Autoload issue #225

Closed
jtapia opened this issue Jul 26, 2022 · 7 comments
Closed

Autoload issue #225

jtapia opened this issue Jul 26, 2022 · 7 comments

Comments

@jtapia
Copy link
Contributor

jtapia commented Jul 26, 2022

Description

We upgraded Solidus from 2.11 to 3.1.0 and we have an user model decorator, after the upgrade we started noticiting that if change and reload any code related to user decorator, it triggers an autoload error
undefined local variable or method acts_as_paranoid for Spree::User:Class

for some reason here https://github.com/solidusio/solidus_auth_devise/blob/master/app/models/spree/user.rb#L11= is not finding the Spree::SoftDeletable module, tried to use acts_as_paranoid but all the references were removed here 11b9fa9

Gemfile

gem 'rails', '6.1.4.1'
gem 'solidus', '3.1.0'
gem 'solidus_support'
gem 'solidus_auth_devise'
gem 'solidus_paypal_commerce_platform'

Decorator

module Decorators
  module Spree
    module User
      def self.prepended(base)
        base.class_eval do
          ...
          ...
        end
      end
    end
  end
end

Log

Started GET "/account/products" for ::1 at 2022-07-26 12:08:03 -0500

NameError (undefined local variable or method `acts_as_paranoid' for Spree::User:Class
Did you mean?  acts_as_list):

activerecord (6.1.4.1) lib/active_record/dynamic_matchers.rb:22:in `method_missing'
solidus_auth_devise (2.5.4) app/models/spree/user.rb:14:in `<class:User>'
solidus_auth_devise (2.5.4) app/models/spree/user.rb:4:in `<module:Spree>'
solidus_auth_devise (2.5.4) app/models/spree/user.rb:3:in `<main>'
bootsnap (1.12.0) lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:39:in `load'
bootsnap (1.12.0) lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:39:in `load'
activesupport (6.1.4.1) lib/active_support/dependencies.rb:523:in `block in load_file'
activesupport (6.1.4.1) lib/active_support/dependencies.rb:715:in `new_constants_in'
activesupport (6.1.4.1) lib/active_support/dependencies.rb:522:in `load_file'
activesupport (6.1.4.1) lib/active_support/dependencies.rb:419:in `block in require_or_load'
activesupport (6.1.4.1) lib/active_support/dependencies.rb:39:in `block in load_interlock'
activesupport (6.1.4.1) lib/active_support/dependencies/interlock.rb:14:in `block in loading'
activesupport (6.1.4.1) lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
activesupport (6.1.4.1) lib/active_support/dependencies/interlock.rb:13:in `loading'
activesupport (6.1.4.1) lib/active_support/dependencies.rb:39:in `load_interlock'
activesupport (6.1.4.1) lib/active_support/dependencies.rb:402:in `require_or_load'
activesupport (6.1.4.1) lib/active_support/dependencies.rb:558:in `load_missing_constant'
activesupport (6.1.4.1) lib/active_support/dependencies.rb:213:in `const_missing'
activesupport (6.1.4.1) lib/active_support/inflector/methods.rb:288:in `const_get'
activesupport (6.1.4.1) lib/active_support/inflector/methods.rb:288:in `block in constantize'
activesupport (6.1.4.1) lib/active_support/inflector/methods.rb:284:in `each'
activesupport (6.1.4.1) lib/active_support/inflector/methods.rb:284:in `inject'
activesupport (6.1.4.1) lib/active_support/inflector/methods.rb:284:in `constantize'
activesupport (6.1.4.1) lib/active_support/dependencies.rb:636:in `get'
activesupport (6.1.4.1) lib/active_support/dependencies.rb:667:in `constantize'
devise (4.8.1) lib/devise.rb:318:in `get'
devise (4.8.1) lib/devise/mapping.rb:83:in `to'
devise (4.8.1) lib/devise/mapping.rb:78:in `modules'
devise (4.8.1) lib/devise/mapping.rb:95:in `routes'
devise (4.8.1) lib/devise/mapping.rb:162:in `default_used_route'
devise (4.8.1) lib/devise/mapping.rb:72:in `initialize'
devise (4.8.1) lib/devise.rb:354:in `new'
devise (4.8.1) lib/devise.rb:354:in `add_mapping'
devise (4.8.1) lib/devise/rails/routes.rb:243:in `block in devise_for'
devise (4.8.1) lib/devise/rails/routes.rb:242:in `each'
devise (4.8.1) lib/devise/rails/routes.rb:242:in `devise_for'
solidus_auth_devise (2.5.4) config/routes.rb:5:in `block in <main>'
actionpack (6.1.4.1) lib/action_dispatch/routing/mapper.rb:655:in `instance_exec'
actionpack (6.1.4.1) lib/action_dispatch/routing/mapper.rb:655:in `block in with_default_scope'
actionpack (6.1.4.1) lib/action_dispatch/routing/mapper.rb:901:in `scope'
actionpack (6.1.4.1) lib/action_dispatch/routing/mapper.rb:654:in `with_default_scope'
actionpack (6.1.4.1) lib/action_dispatch/routing/route_set.rb:425:in `eval_block'
actionpack (6.1.4.1) lib/action_dispatch/routing/route_set.rb:409:in `draw'
solidus_auth_devise (2.5.4) config/routes.rb:3:in `<main>'
bootsnap (1.12.0) lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:39:in `load'
bootsnap (1.12.0) lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:39:in `load'
activesupport (6.1.4.1) lib/active_support/dependencies.rb:326:in `block in load'
activesupport (6.1.4.1) lib/active_support/dependencies.rb:299:in `load_dependency'
activesupport (6.1.4.1) lib/active_support/dependencies.rb:326:in `load'
railties (6.1.4.1) lib/rails/application/routes_reloader.rb:47:in `block in load_paths'
railties (6.1.4.1) lib/rails/application/routes_reloader.rb:47:in `each'
railties (6.1.4.1) lib/rails/application/routes_reloader.rb:47:in `load_paths'
railties (6.1.4.1) lib/rails/application/routes_reloader.rb:21:in `reload!'
railties (6.1.4.1) lib/rails/application/routes_reloader.rb:35:in `block in updater'
activesupport (6.1.4.1) lib/active_support/file_update_checker.rb:83:in `execute'
railties (6.1.4.1) lib/rails/application/routes_reloader.rb:10:in `execute'
railties (6.1.4.1) lib/rails/application/finisher.rb:208:in `block (2 levels) in <module:Finisher>'
activesupport (6.1.4.1) lib/active_support/callbacks.rb:427:in `instance_exec'
activesupport (6.1.4.1) lib/active_support/callbacks.rb:427:in `block in make_lambda'
activesupport (6.1.4.1) lib/active_support/callbacks.rb:198:in `block (2 levels) in halting'
activesupport (6.1.4.1) lib/active_support/callbacks.rb:604:in `block (2 levels) in default_terminator'
activesupport (6.1.4.1) lib/active_support/callbacks.rb:603:in `catch'
activesupport (6.1.4.1) lib/active_support/callbacks.rb:603:in `block in default_terminator'
activesupport (6.1.4.1) lib/active_support/callbacks.rb:199:in `block in halting'
activesupport (6.1.4.1) lib/active_support/callbacks.rb:512:in `block in invoke_before'
activesupport (6.1.4.1) lib/active_support/callbacks.rb:512:in `each'
activesupport (6.1.4.1) lib/active_support/callbacks.rb:512:in `invoke_before'
activesupport (6.1.4.1) lib/active_support/callbacks.rb:105:in `run_callbacks'
activesupport (6.1.4.1) lib/active_support/execution_wrapper.rb:111:in `run!'
activesupport (6.1.4.1) lib/active_support/reloader.rb:114:in `run!'
activesupport (6.1.4.1) lib/active_support/execution_wrapper.rb:73:in `block in run!'
<internal:kernel>:90:in `tap'
activesupport (6.1.4.1) lib/active_support/execution_wrapper.rb:70:in `run!'
activesupport (6.1.4.1) lib/active_support/reloader.rb:63:in `run!'
actionpack (6.1.4.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
actionpack (6.1.4.1) lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
sentry-rails (5.4.1) lib/sentry/rails/rescued_exception_interceptor.rb:9:in `call'
actionpack (6.1.4.1) lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call'
web-console (4.2.0) lib/web_console/middleware.rb:132:in `call_app'
web-console (4.2.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (4.2.0) lib/web_console/middleware.rb:17:in `catch'
web-console (4.2.0) lib/web_console/middleware.rb:17:in `call'
sentry-ruby (5.4.1) lib/sentry/rack/capture_exceptions.rb:13:in `call'
actionpack (6.1.4.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (6.1.4.1) lib/rails/rack/logger.rb:37:in `call_app'
railties (6.1.4.1) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (6.1.4.1) lib/active_support/tagged_logging.rb:99:in `block in tagged'
activesupport (6.1.4.1) lib/active_support/tagged_logging.rb:37:in `tagged'
activesupport (6.1.4.1) lib/active_support/tagged_logging.rb:99:in `tagged'
railties (6.1.4.1) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.4.2) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (6.1.4.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (6.1.4.1) lib/action_dispatch/middleware/request_id.rb:26:in `call'
rack (2.2.4) lib/rack/method_override.rb:24:in `call'
rack (2.2.4) lib/rack/runtime.rb:22:in `call'
activesupport (6.1.4.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (6.1.4.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.1.4.1) lib/action_dispatch/middleware/static.rb:24:in `call'
rack (2.2.4) lib/rack/sendfile.rb:110:in `call'
actionpack (6.1.4.1) lib/action_dispatch/middleware/host_authorization.rb:98:in `call'
webpacker (5.4.3) lib/webpacker/dev_server_proxy.rb:25:in `perform_request'
rack-proxy (0.7.2) lib/rack/proxy.rb:67:in `call'
railties (6.1.4.1) lib/rails/engine.rb:539:in `call'
rack-reverse-proxy (0.11.0) lib/rack_reverse_proxy/roundtrip.rb:19:in `call'
rack-reverse-proxy (0.11.0) lib/rack_reverse_proxy/middleware.rb:25:in `call'
puma (4.3.12) lib/puma/configuration.rb:228:in `call'
puma (4.3.12) lib/puma/server.rb:727:in `handle_request'
puma (4.3.12) lib/puma/server.rb:476:in `process_client'
puma (4.3.12) lib/puma/server.rb:332:in `block in run'
puma (4.3.12) lib/puma/thread_pool.rb:134:in `block in spawn_thread'
@jarednorman
Copy link
Member

Thanks for creating this issue. The context is really helpful.

As I mentioned in the original PR over here, this issue is presumably caused by the load order causing the SoftDeletable concern not to be available when the Spree::User model is reloaded, causing it to attempt to use the pre-SoftDeletable paranoia code path, and blowing up.

My assumption is currently that we need to do something to ensure that the module is available, but if we're at the point where we (@solidusio/core-team) are happy to remove paranoia support fully from solidus_auth_devise, we could go the route that you came up with in #223.

gsmendoza added a commit to gsmendoza/rails_6141_store that referenced this issue Jul 27, 2022
solidusio/solidus_auth_devise#225

Scenario: I should be able to reload the app after changing a user
decorator

Given I am logged in
When I go to the the account page
Then I should see the value of UserDecorator#decoration
When I change the value the UserDecorator#decoration
And I refresh the account page
Then I should see the new value
@gsmendoza
Copy link
Contributor

Hello @jtapia @jarednorman ! I'm not sure if there is still a need to reproduce the issue encountered here, but just the same, I tried it out, and I haven't been successful so far :) Please watch the video below of my test run:

solidus-auth-devise-225-2022-07-27-manual-test.mp4

You can find the test app at https://github.com/gsmendoza/rails_6141_store/tree/solidus_auth_devise_225.

As I said in the video, if you have any suggestions on how I can update the app to reproduce the issue, please let me know. Thanks!

@jarednorman
Copy link
Member

I wonder if there's a reference to the user model somewhere in the apps of the people hitting this issue that's changing the order the classes get loaded or something.

@jakemumu
Copy link

jakemumu commented Feb 8, 2023

I re-visited this today, we had made a fork and removed that code which was causing us issues for the time being. This issue stopped presenting itself... I'm not really sure what was going on with the load order which was appearing to make this go wrong but I think it's safe to close this issue.

@AlistairNorman
Copy link

I found that upgrading from the classic autoloader to Zeitwerk fixed this issue for me.

@kennyadsl
Copy link
Member

Going to close this, if it happens again, feel free to comment!

@Noah-Silvera
Copy link

Adding this require to the top of my application.rb also fixed this without having to upgrade to zeitwerk

gem_dir = Gem::Specification.find_by_name("solidus_core").gem_dir
require "#{gem_dir}/app/models/concerns/spree/soft_deletable"

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

7 participants