blacklight
blacklight copied to clipboard
v5.18 triggers "ActiveSupport::Concern::MultipleIncludedBlocks: Cannot define multiple 'included' blocks for a Concern"
I am using Blacklight along with sunspot. Since recently we stuck with version 5.14, but today I updated my bundle to 5.18. After the update I found that reindexing in sunspot was broken and would crash with a "ActiveSupport::Concern::MultipleIncludedBlocks: Cannot define multiple 'included' blocks for a Concern" expection. in document.rb:
bundle exec rake sunspot:reindex[,Source]
rake aborted!
ActiveSupport::Concern::MultipleIncludedBlocks: Cannot define multiple 'included' blocks for a Concern
/Users/xhero/.rvm/gems/ruby-2.1.8@rails42/gems/activesupport-4.2.5.2/lib/active_support/concern.rb:126:in `included'
/Users/xhero/.rvm/gems/ruby-2.1.8@rails42/gems/blacklight-5.18.0/app/models/concerns/blacklight/document.rb:31:in `<module:Document>'
/Users/xhero/.rvm/gems/ruby-2.1.8@rails42/gems/blacklight-5.18.0/app/models/concerns/blacklight/document.rb:15:in `<top (required)>'
/Users/xhero/.rvm/gems/ruby-2.1.8@rails42/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:457:in `load'
/Users/xhero/.rvm/gems/ruby-2.1.8@rails42/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:457:in `block in load_file'
/Users/xhero/.rvm/gems/ruby-2.1.8@rails42/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:647:in `new_constants_in'
/Users/xhero/.rvm/gems/ruby-2.1.8@rails42/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:456:in `load_file'
/Users/xhero/.rvm/gems/ruby-2.1.8@rails42/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:354:in `require_or_load'
/Users/xhero/.rvm/gems/ruby-2.1.8@rails42/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:317:in `depend_on'
/Users/xhero/.rvm/gems/ruby-2.1.8@rails42/gems/activesupport-4.2.5.2/lib/active_support/dependencies.rb:233:in `require_dependency'
/Users/xhero/.rvm/gems/ruby-2.1.8@rails42/gems/railties-4.2.5.2/lib/rails/engine.rb:472:in `block (2 levels) in eager_load!'
/Users/xhero/.rvm/gems/ruby-2.1.8@rails42/gems/railties-4.2.5.2/lib/rails/engine.rb:471:in `each'
/Users/xhero/.rvm/gems/ruby-2.1.8@rails42/gems/railties-4.2.5.2/lib/rails/engine.rb:471:in `block in eager_load!'
/Users/xhero/.rvm/gems/ruby-2.1.8@rails42/gems/railties-4.2.5.2/lib/rails/engine.rb:469:in `each'
/Users/xhero/.rvm/gems/ruby-2.1.8@rails42/gems/railties-4.2.5.2/lib/rails/engine.rb:469:in `eager_load!'
/Users/xhero/.rvm/gems/ruby-2.1.8@rails42/bundler/gems/sunspot-9c4ec23487d4/sunspot_rails/lib/sunspot/rails/tasks.rb:34:in `block (4 levels) in <top (required)>'
/Users/xhero/.rvm/gems/ruby-2.1.8@rails42/bundler/gems/sunspot-9c4ec23487d4/sunspot_rails/lib/sunspot/rails/tasks.rb:34:in `each'
/Users/xhero/.rvm/gems/ruby-2.1.8@rails42/bundler/gems/sunspot-9c4ec23487d4/sunspot_rails/lib/sunspot/rails/tasks.rb:34:in `block (3 levels) in <top (required)>'
/Users/xhero/.rvm/gems/ruby-2.1.8@rails42/bundler/gems/sunspot-9c4ec23487d4/sunspot_rails/lib/sunspot/rails/tasks.rb:69:in `with_session'
/Users/xhero/.rvm/gems/ruby-2.1.8@rails42/bundler/gems/sunspot-9c4ec23487d4/sunspot_rails/lib/sunspot/rails/tasks.rb:19:in `block (2 levels) in <top (required)>'
/Users/xhero/.rvm/gems/ruby-2.1.8@rails42/bin/ruby_executable_hooks:15:in `eval'
/Users/xhero/.rvm/gems/ruby-2.1.8@rails42/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => sunspot:reindex
(See full trace by running task with --trace)
The file document.rb is included two times. After much debugging I found the culprit in lib/blacklight/solr.rb, which explicitly requires the file:
require File.join(Blacklight::Engine.config.root, 'app', 'models', 'concerns', 'blacklight', 'document')
require File.join(Blacklight::Engine.config.root, 'app', 'models', 'concerns', 'blacklight', 'solr', 'document')
If I comment the two lines the exception disappears and blacklight still seems to work. The explicit require was added in v.5.18 in 89324061a5666115afeb2bdcb373705dafa0c4de. I looked at the 6.01 release and the two explicit requires are not there. Any reason for the explicit require? Rails seems to be able to autoload all the files without them. In my shop we are not (yet) ready to migrate to version 6, so a working 5.x is appreciated. For the moment we rolled back to 5.14.
Same issue still exists in 5.x series. Latest 5.x release 5.19.2
https://github.com/projectblacklight/blacklight/blob/e7764c1e58bb10b5ea2e186c68e1e320d42c1fb3/app/models/concerns/blacklight/document.rb#L18
using require_relative. Fixed in 6.x series by using autoload
https://github.com/projectblacklight/blacklight/blob/1c56e366550792224d98c03f30357cb4f15d289c/app/models/concerns/blacklight/document.rb#L17