spree-contrib / spree_multi_vendor

Spree marketplace extension. Create your own marketplace on top of Spree Commerce
https://spreecommerce.org/marketplace-ecommerce/
BSD 3-Clause "New" or "Revised" License
142 stars 135 forks source link

uninitialized constant Spree::Preferences (NameError) #221

Closed marocchino closed 1 year ago

marocchino commented 1 year ago

There is a loading issue after updating to version 2.4.0.

ruby '3.2.0'
gem 'rails', '6.1.6'
gem 'spree', '4.3.2'
gem 'spree_multi_vendor', '2.4.0'
...
$ rails c
/Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/spree_multi_vendor-2.4.0/lib/spree_multi_vendor/configuration.rb:2:in `<module:SpreeMultiVendor>': uninitialized constant Spree::Preferences (NameError)
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/spree_multi_vendor-2.4.0/lib/spree_multi_vendor/configuration.rb:1:in `<main>'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/spree_multi_vendor-2.4.0/lib/spree_multi_vendor/engine.rb:1:in `require_relative'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/spree_multi_vendor-2.4.0/lib/spree_multi_vendor/engine.rb:1:in `<main>'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/spree_multi_vendor-2.4.0/lib/spree_multi_vendor.rb:4:in `<main>'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-2.4.3/lib/bundler/runtime.rb:60:in `block (2 levels) in require'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-2.4.3/lib/bundler/runtime.rb:55:in `each'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-2.4.3/lib/bundler/runtime.rb:55:in `block in require'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-2.4.3/lib/bundler/runtime.rb:44:in `each'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-2.4.3/lib/bundler/runtime.rb:44:in `require'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-2.4.3/lib/bundler.rb:195:in `require'
    from /Users/marocchino/Documents/smv/config/application.rb:7:in `<main>'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/railties-6.1.6/lib/rails/command/actions.rb:22:in `require_application!'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/railties-6.1.6/lib/rails/command/actions.rb:14:in `require_application_and_environment!'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/railties-6.1.6/lib/rails/commands/console/console_command.rb:101:in `perform'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/railties-6.1.6/lib/rails/command/base.rb:69:in `perform'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/railties-6.1.6/lib/rails/command.rb:48:in `invoke'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/railties-6.1.6/lib/rails/commands.rb:18:in `<main>'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
    from /Users/marocchino/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/bootsnap-1.15.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
marocchino commented 1 year ago

This seems to be due to the file location change in spree itself. https://github.com/spree/spree/blob/v4.3.2/core/app/models/spree/preferences/configuration.rb https://github.com/spree/spree/blob/v4.5.0/core/lib/spree/core/preferences/configuration.rb

It looks like you need to either update the minimum required version or makes condition for before 4.5.

related #218, https://github.com/spree/spree/pull/11552

rafalcymerys commented 1 year ago

Hi @marocchino - thank you for reporting this. I reviewed the issue and it doesn't even make sense to inherit from Spree::Preference for this, as vendorized models don't make sense to be persisted into the database. I've made some adjustments in this PR and released v2.4.1 It should work fine now, and in case of any problems, please reopen this issue