padrino-framework
padrino-framework copied to clipboard
error occurred when I modify source code (padrino is running)
ERROR - ActiveSupport::Concern::MultipleIncludedBlocks - Cannot define multiple 'included' blocks for a Concern:
/home/ssut/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.1.0/lib/active_support/concern.rb:126:in `included'
ERROR - Failed to load /home/ssut/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.1.0/lib/active_support/logger_silence.rb; removing partially defined constants
ERROR - ActiveSupport::Concern::MultipleIncludedBlocks - Cannot define multiple 'included' blocks for a Concern:
/home/ssut/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activesupport-4.1.0/lib/active_support/concern.rb:126:in `included'
An error occurred when I modify source code. *prerequisite: padrino is running and reload option is on.
@ssut Thanks for the report! However, I couldn't reproduce. Please, provide a failing project.
(It's just a guess) I need active_support/time module, and I was required to 'active_support/time' in controllers. So, I modified controller and padrino will reload changes(file). The problem is occured here. It seems the problem was in this case, active_support is necessary to require only once.
Thanks, confirmed. We will investigate the issue.
I've digged in the issue. @ssut quick fix:
require 'active_support/time' unless defined?(ActiveSupport::Duration)
@ujifgc @padrino/core-members
Padrino::Reloader.safe_load
fails because ActiveSupport prohibits including the multiple block.
https://github.com/rails/rails/blob/v4.1.0/activesupport/lib/active_support/logger_silence.rb#L6-L9
https://github.com/rails/rails/blob/v4.1.0/activesupport/lib/active_support/concern.rb#L126
Perhaps, we should provide a method that can avoid loading specific external library. What do you think?
Does the app fail every time the source is changed or only when require 'active_support/time'
gets added?
Yes, this error occurs everytime the source is changed.
This commit 8e23d810ee507507754433cb5c1dd142b0c23ec7 can possibly fix #1583 earlier marked as [wontfix].
Great! I had assumed that external library was target of the reloader.
Thanks for fix this issue! :)
I'm getting the same error but I'm not using an external library.
I have a module that extend ActiveSupport::Concern and is included into a model. I created a dummy project here: https://github.com/senekis/dashboard to reproduce the error.
Steps to reproduce:
- Starts the padrino application
- Open / in a browser
- Modify the file: user_mixins/filters.rb
- Reload / in the browser
You'll see the error ActiveSupport::Concern::MultipleIncludedBlocks - Cannot define multiple 'included' blocks for a Concern:
I appreciate your help
Should be fixed on master by d25298caba28bf7a7157bd7475736ad129365525
The fix broke reloading apps. Reverted it by 579944b6304917bf8213bcb00d5f228704b6a672.
Temporary solution: don't use ActiveSupport::Concern
and other techniques dependent on mutating module instance variables.
👍 faced the same issue, i guess since production no reload, it should work, but on development, we need to restart on concern change
from my finding, adding this in my concern file
Object.send(:remove_const, :<ConcernClass>) if Object.constants.include?(:<ConcernClass>)
fixed the issue, but some how the model class that include this concern class will need to reload too... otherwise the model class will be using the old concern (havent reload ConcernClass module)
i tried to remove activeconcern from my concerns/tokenable.rb but i realize, when i modify this file, the actual file that include this file will not reload Example:
# ruby way
module Tokenable
def self.included(klass)
klass.before_validation :yahoo
end
def yahoo
puts "aaaaa"
self.token = "aaaaa"
end
# models/aaa.rb
class Aaa < ActiveRecord::Base
include Tokenable
end
when i run in padrino console, i modified file concerns/tokenable.rb and change my up and token assignment to "bbbb", then i ran reload! and Tried
row = Aaa.new
row.valid?
# output "aaaaa"
# expected "bbbb"
okay, ive a fix, can someone verify that this works with few rspec? :)
it detects reloading of concern file, then find all models that include the file, and try to locate the file for reload, and remove the constant from session, and finally load it in the end
https://gist.github.com/u007/47b2f021670d54f862624ae70494a085
okay, ive a fix, can someone verify that this works with few rspec? :)
it detects reloading of concern file, then find all models that include the file, and try to locate the file for reload, and remove the constant from session, and finally load it in the end
https://gist.github.com/u007/47b2f021670d54f862624ae70494a085
It works, thanks!