decidim / decidim

The participatory democracy framework. A generator and multiple gems made with Ruby on Rails
https://decidim.org/
GNU Affero General Public License v3.0
1.48k stars 405 forks source link

Initializer generates uninitialized constant error when not all decidim modules are enabled #9423

Closed alecslupu closed 2 years ago

alecslupu commented 2 years ago

Describe the bug I am trying to install a decidim custom version of the application, without having all the decidim modules ( i am not interested in having Budgets, Accountability etc)

I have added to my gemfile


DECIDIM_VERSION = { git: "https://github.com/decidim/decidim", branch: "develop" }

# This is extracted from main decidim.gemspec
# gem "decidim-accountability", DECIDIM_VERSION
gem "decidim-admin", DECIDIM_VERSION
gem "decidim-api", DECIDIM_VERSION
gem "decidim-assemblies", DECIDIM_VERSION
gem "decidim-blogs", DECIDIM_VERSION
# gem "decidim-budgets", DECIDIM_VERSION
gem "decidim-comments", DECIDIM_VERSION
gem "decidim-core", DECIDIM_VERSION
# gem "decidim-debates", DECIDIM_VERSION
gem "decidim-forms", DECIDIM_VERSION
# gem "decidim-generators", DECIDIM_VERSION
gem "decidim-meetings", DECIDIM_VERSION
gem "decidim-pages", DECIDIM_VERSION
gem "decidim-participatory_processes", DECIDIM_VERSION
gem "decidim-proposals", DECIDIM_VERSION
# gem "decidim-sortitions", DECIDIM_VERSION
gem "decidim-surveys", DECIDIM_VERSION
gem "decidim-system", DECIDIM_VERSION
# gem "decidim-templates", DECIDIM_VERSION
gem "decidim-verifications", DECIDIM_VERSION

# gem "decidim-conferences", DECIDIM_VERSION
# gem "decidim-consultations", DECIDIM_VERSION
# gem "decidim-elections", DECIDIM_VERSION
# gem "decidim-initiatives", DECIDIM_VERSION
# EOF This is extracted from main decidim.gemspec

When attempting to boot the application, using the above Gemfile configuration, i get an error like: uninitialized constant Decidim::Budgets (NameError)

To Reproduce Steps to reproduce the behavior:

  1. Generate a new application
  2. Replace the decidim installation as above
  3. Run bundle install
  4. Run rails console
  5. See error

Expected behavior The application should boot normally.

Stacktrace

\/code/config/initializers/decidim.rb:418:in `<main>': uninitialized constant Decidim::Budgets (NameError)
    from /bundle_cache/ruby/3.0.0/gems/bootsnap-1.12.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:39:in `load'
    from /bundle_cache/ruby/3.0.0/gems/bootsnap-1.12.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:39:in `load'
    from /bundle_cache/ruby/3.0.0/gems/railties-6.1.6/lib/rails/engine.rb:681:in `block in load_config_initializer'
    from /bundle_cache/ruby/3.0.0/gems/activesupport-6.1.6/lib/active_support/notifications.rb:205:in `instrument'
    from /bundle_cache/ruby/3.0.0/gems/railties-6.1.6/lib/rails/engine.rb:680:in `load_config_initializer'
    from /bundle_cache/ruby/3.0.0/gems/railties-6.1.6/lib/rails/engine.rb:634:in `block (2 levels) in <class:Engine>'
    from /bundle_cache/ruby/3.0.0/gems/railties-6.1.6/lib/rails/engine.rb:633:in `each'
    from /bundle_cache/ruby/3.0.0/gems/railties-6.1.6/lib/rails/engine.rb:633:in `block in <class:Engine>'
    from /bundle_cache/ruby/3.0.0/gems/railties-6.1.6/lib/rails/initializable.rb:32:in `instance_exec'
    from /bundle_cache/ruby/3.0.0/gems/railties-6.1.6/lib/rails/initializable.rb:32:in `run'
    from /bundle_cache/ruby/3.0.0/gems/railties-6.1.6/lib/rails/initializable.rb:61:in `block in run_initializers'
    from /usr/local/lib/ruby/3.0.0/tsort.rb:228:in `block in tsort_each'
    from /usr/local/lib/ruby/3.0.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    from /usr/local/lib/ruby/3.0.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
    from /usr/local/lib/ruby/3.0.0/tsort.rb:431:in `each_strongly_connected_component_from'
    from /usr/local/lib/ruby/3.0.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
    from /bundle_cache/ruby/3.0.0/gems/railties-6.1.6/lib/rails/initializable.rb:50:in `each'
    from /bundle_cache/ruby/3.0.0/gems/railties-6.1.6/lib/rails/initializable.rb:50:in `tsort_each_child'
    from /usr/local/lib/ruby/3.0.0/tsort.rb:415:in `call'
    from /usr/local/lib/ruby/3.0.0/tsort.rb:415:in `each_strongly_connected_component_from'
    from /usr/local/lib/ruby/3.0.0/tsort.rb:349:in `block in each_strongly_connected_component'
    from /usr/local/lib/ruby/3.0.0/tsort.rb:347:in `each'
    from /usr/local/lib/ruby/3.0.0/tsort.rb:347:in `call'
    from /usr/local/lib/ruby/3.0.0/tsort.rb:347:in `each_strongly_connected_component'
    from /usr/local/lib/ruby/3.0.0/tsort.rb:226:in `tsort_each'
    from /usr/local/lib/ruby/3.0.0/tsort.rb:205:in `tsort_each'
    from /bundle_cache/ruby/3.0.0/gems/railties-6.1.6/lib/rails/initializable.rb:60:in `run_initializers'
    from /bundle_cache/ruby/3.0.0/gems/railties-6.1.6/lib/rails/application.rb:391:in `initialize!'
    from /code/config/environment.rb:5:in `<main>'
    from /bundle_cache/ruby/3.0.0/gems/bootsnap-1.12.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
    from /bundle_cache/ruby/3.0.0/gems/bootsnap-1.12.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
    from /bundle_cache/ruby/3.0.0/gems/zeitwerk-2.5.4/lib/zeitwerk/kernel.rb:35:in `require'
    from /bundle_cache/ruby/3.0.0/gems/spring-2.1.1/lib/spring/application.rb:106:in `preload'
    from /bundle_cache/ruby/3.0.0/gems/spring-2.1.1/lib/spring/application.rb:157:in `serve'
    from /bundle_cache/ruby/3.0.0/gems/spring-2.1.1/lib/spring/application.rb:145:in `block in run'
    from /bundle_cache/ruby/3.0.0/gems/spring-2.1.1/lib/spring/application.rb:139:in `loop'
    from /bundle_cache/ruby/3.0.0/gems/spring-2.1.1/lib/spring/application.rb:139:in `run'
    from /bundle_cache/ruby/3.0.0/gems/spring-2.1.1/lib/spring/application/boot.rb:19:in `<top (required)>'
    from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
    from <internal:/usr/local/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
    from -e:1:in `<main>'

Extra data (please complete the following information):

Additional context N/A

andreslucena commented 2 years ago

Confirmed locally.

Relevant snippet:

if Decidim.module_installed? :budgets    
  Decidim::Budgets.configure do |config|    
    unless Rails.application.secrets.dig(:decidim, :budgets, :enable_proposal_linking) == "auto"    
      config.enable_proposal_linking = Rails.application.secrets.dig(:decidim, :budgets, :enable_proposal_linking).present? 
    end    
  end    
end

The line that gives the error is Decidim::Budgets.configure do |config|, so the culprit is probably the Decidim.module_installed? method.

ahukkanen commented 2 years ago

Potential fix seems to be cooking at #9502.

It's not fixing this issue particularly but as a side-effect I believe it will fix this one too. Have to be confirmed still, though.

ahukkanen commented 2 years ago

9502 did not provide solution to this as stated in the review of that PR.

9577 should fix this issue instead.