-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
warning: already initialized constant Merit::AppBadgeRules #173
Comments
This is due to explicit loading by Rails. To fix this, change: Merit::AppBadgeRules = Merit::BadgeRules.new.defined_rules
Merit::AppPointRules = Merit::PointRules.new.defined_rules to Merit::AppBadgeRules ||= Merit::BadgeRules.new.defined_rules
Merit::AppPointRules ||= Merit::PointRules.new.defined_rules |
That's weird, I don't get that error. Why would it be loading twice? Your proposed fix would affect code reloading in development: if you edit rules and not restart the server, merit won't see them. Can you please post your |
Hi @tute, my Gemfile below:
|
Thanks for your input. I'll need a failing application in Github to reproduce/debug though. |
@emaillenin how can I replicate this error? |
@tute - Can you try creating an app with all the gems I listed above? |
From the Gemfile I can recreate apps that don't show that behavior. What you described could be caused by application code, exact Ruby version (which patch level?), etc. |
Closing for now until we can reproduce. Thanks! |
Was looking at this issue again. I kept a binding.pry in lib/merit.rb ActiveSupport.on_load(:action_controller) do
begin
# Load app rules on boot up
binding.pry
Merit::AppBadgeRules = Merit::BadgeRules.new.defined_rules
Merit::AppPointRules = Merit::PointRules.new.defined_rules
include Merit::ControllerExtensions
rescue NameError => e
# Trap NameError if installing/generating files
raise e unless e.to_s =~ /uninitialized constant Merit::BadgeRules/
end
end And started the rails server. I hit this breakpoint twice. But pry-backtrace reveals the same trace for the both the times. /Users/leninraj/.rvm/gems/ruby-2.1.2/gems/merit-2.1.1/lib/merit.rb:83:in `block (2 levels) in <class:Engine>'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/lazy_load_hooks.rb:27:in `each'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/merit-2.1.1/lib/merit.rb:80:in `block in <class:Engine>'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `instance_exec'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `run'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/leninraj/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
/Users/leninraj/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
/Users/leninraj/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
/Users/leninraj/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
/Users/leninraj/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each'
/Users/leninraj/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `call'
/Users/leninraj/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
/Users/leninraj/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
/Users/leninraj/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/initializable.rb:54:in `run_initializers'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application.rb:300:in `initialize!'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/railtie.rb:194:in `public_send'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/railtie.rb:194:in `method_missing'
/Users/leninraj/Dropbox/Projects/duggout/duggout/config/environment.rb:5:in `<top (required)>'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `block in require'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:232:in `load_dependency'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:247:in `require'
/Users/leninraj/Dropbox/Projects/duggout/duggout/config.ru:3:in `block in <main>'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
/Users/leninraj/Dropbox/Projects/duggout/duggout/config.ru:in `new'
/Users/leninraj/Dropbox/Projects/duggout/duggout/config.ru:in `<main>'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands/server.rb:50:in `app'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands/server.rb:130:in `log_to_stdout'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands/server.rb:67:in `start'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:81:in `block in server'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:76:in `tap'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:76:in `server'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
/Users/leninraj/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/commands.rb:17:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>' Can you spot anything weird in the trace? |
I'm getting the same warning message.
|
getting same warning. |
Getting the same warning as well:
Using:
|
I wonder why would we hit |
I'm seeing these warnings as well:
|
In reply to @zokioki which has a very similar setup to mine. I'm not getting this problem
There is a problem with Ruby 2.3.0, so you might want to update to 2.3.1 |
@pacMakaveli I've updated Ruby, Rails and Merit to exactly match the versions in your setup - the warnings persist for me. |
@zokioki Did you update you bin/* ? Be sure to check config.ru , bin/* and application.rb |
@pacMakaveli Updating the code highlighted in that railsdiff for the rc1 release did the trick for me. Thank you! 👍 |
Changing the highlighted rails diffs code didn't work for me (rake rails:upgrade changed most of those for me already), I still keep getting the same errors, @emaillenin's fix would work for me, my stacktrace is nearly identical when attaching binding.pry. Trace /Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/merit-2.3.4/lib/merit.rb:87:in `block (2 levels) in <class:Engine>'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:27:in `each'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/lazy_load_hooks.rb:27:in `on_load'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/merit-2.3.4/lib/merit.rb:85:in `block in <class:Engine>'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/initializable.rb:30:in `instance_exec'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/initializable.rb:30:in `run'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/jrasanen/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
/Users/jrasanen/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
/Users/jrasanen/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
/Users/jrasanen/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
/Users/jrasanen/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each'
/Users/jrasanen/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `call'
/Users/jrasanen/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
/Users/jrasanen/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
/Users/jrasanen/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/initializable.rb:54:in `run_initializers'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/application.rb:352:in `initialize!'
/Users/jrasanen/Development/ror/stream/s/config/environment.rb:5:in `<top (required)>'
/Users/jrasanen/Development/ror/stream/s/config.ru:2:in `require_relative'
/Users/jrasanen/Development/ror/stream/s/config.ru:2:in `block in <main>'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/builder.rb:55:in `instance_eval'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/builder.rb:55:in `initialize'
/Users/jrasanen/Development/ror/stream/s/config.ru:in `new'
/Users/jrasanen/Development/ror/stream/s/config.ru:in `<main>'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/builder.rb:49:in `eval'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/builder.rb:49:in `new_from_string'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/builder.rb:40:in `parse_file'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/server.rb:318:in `build_app_and_options_from_config'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/server.rb:218:in `app'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/server.rb:59:in `app'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/rack-2.0.1/lib/rack/server.rb:353:in `wrapped_app'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/server.rb:124:in `log_to_stdout'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/server.rb:77:in `start'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:90:in `block in server'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:85:in `tap'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:85:in `server'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
/Users/jrasanen/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<top (required)>' config.ru # This file is used by Rack-based servers to start the application.
require_relative 'config/environment'
run Rails.application application.rb require_relative 'boot'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module S
class Application < Rails::Application
# redacted~
end
end environment.rb # Load the Rails application.
require_relative 'application'
# Initialize the Rails application.
Rails.application.initialize! bin/rails #!/usr/bin/env ruby
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands' |
Fix suggested @ merit-gem#173
applying the suggested solution on merit-gem#173
@zokioki Can you please explain what exactly is changed? I am still getting this error |
ActiveSupport.on_load(:action_controller) is getting called twice , So I don't think this issue is specific to this gem |
After digging more I found the cause, rails calls |
Thank you @redtachyons! It looks like the Thank you again! |
Thanks for the reply, I tried https://gist.github.com/redtachyons/568e0f79804d80f90de12f73353a86a2 this snippet with rails >5.0 & < 5.1.4, it just silently ignored that extra parameter. So adding |
Sounds like finally we have a proper solution! Mind sending in a PR? |
Sure |
Closing in favor of #282. Thank you, @redtachyons! ❤️ |
…ler::Base and ActionController::API. Rails [introduced](rails/rails#30045) `has_one` option to limit executions to one This will fix merit-gem#173 for rails 5.1.4 and above
Rails execute `action_controller` onload hooks for Both ActionController::Base and ActionController::API. Rails [introduced](rails/rails#30045) `has_one` option to limit executions to one This will fix merit-gem#173 for rails 5.1.4 and above
I'm seeing this in our app in the console output of merit (4.0.2)
Adjusting this locally has removed seeing the above warnings: #173 (comment). |
I get the following error while initializing rails console/server while using Merit ~> 2.0. The same warning existing since Merit 2.0.0.
The text was updated successfully, but these errors were encountered: