padrino-framework icon indicating copy to clipboard operation
padrino-framework copied to clipboard

error occurred when I modify source code (padrino is running)

Open ssut opened this issue 10 years ago • 17 comments

  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 avatar Apr 23 '14 01:04 ssut

@ssut Thanks for the report! However, I couldn't reproduce. Please, provide a failing project.

namusyaka avatar May 05 '14 20:05 namusyaka

(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.

ssut avatar May 06 '14 03:05 ssut

Thanks, confirmed. We will investigate the issue.

namusyaka avatar May 06 '14 11:05 namusyaka

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?

namusyaka avatar May 06 '14 17:05 namusyaka

Does the app fail every time the source is changed or only when require 'active_support/time' gets added?

ujifgc avatar May 06 '14 20:05 ujifgc

Yes, this error occurs everytime the source is changed.

namusyaka avatar May 06 '14 22:05 namusyaka

This commit 8e23d810ee507507754433cb5c1dd142b0c23ec7 can possibly fix #1583 earlier marked as [wontfix].

ujifgc avatar May 07 '14 15:05 ujifgc

Great! I had assumed that external library was target of the reloader.

namusyaka avatar May 07 '14 15:05 namusyaka

Thanks for fix this issue! :)

ssut avatar May 08 '14 06:05 ssut

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:

  1. Starts the padrino application
  2. Open / in a browser
  3. Modify the file: user_mixins/filters.rb
  4. Reload / in the browser

You'll see the error ActiveSupport::Concern::MultipleIncludedBlocks - Cannot define multiple 'included' blocks for a Concern:

I appreciate your help

senekis avatar May 10 '16 16:05 senekis

Should be fixed on master by d25298caba28bf7a7157bd7475736ad129365525

ujifgc avatar May 11 '16 10:05 ujifgc

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.

ujifgc avatar May 11 '16 13:05 ujifgc

👍 faced the same issue, i guess since production no reload, it should work, but on development, we need to restart on concern change

u007 avatar Jul 22 '16 16:07 u007

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)

u007 avatar Jul 22 '16 16:07 u007

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"

u007 avatar Jul 24 '16 08:07 u007

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

u007 avatar Jul 24 '16 12:07 u007

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!

debbbbie avatar Jan 08 '19 01:01 debbbbie