Project

General

Profile

Actions

Defect #38155

closed

RuntimeError when reloading Rails console

Added by Thomas Löber about 1 year ago. Updated 15 days ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Rails support
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

Hi!

When I start a Rails console in development and at some point run a reload! to reload changes I have just made to the source code, I get a RuntimeError:

> rails console
Loading development environment (Rails 6.1.7)
irb(main):001:0> reload!
Reloading...
Traceback (most recent call last):
        7: from config/initializers/30-redmine.rb:11:in `block in <top (required)>'
        6: from lib/redmine/preparation.rb:163:in `prepare'
        5: from lib/redmine/menu_manager.rb:251:in `map'
        4: from lib/redmine/preparation.rb:164:in `block in prepare'
        3: from lib/redmine/menu_manager.rb:321:in `push'
        2: from lib/redmine/menu_manager.rb:403:in `add'
        1: from lib/redmine/menu_manager.rb:386:in `add_at'
RuntimeError (Child already added)

The source of the error is Redmine::Preparation.prepare, which is called in this to_prepare block in config/initializers/30-redmine.rb:

Rails.application.config.to_prepare do
  I18n.backend = Redmine::I18n::Backend.new
  # Forces I18n to load available locales from the backend
  I18n.config.available_locales = nil

  Redmine::Preparation.prepare
end

The reason for the error is that Rails.application.reloader.reload! correctly runs the prepare callbacks twice, but Redmine::Preparation.prepare does not support being called multiple times.

From https://github.com/rails/rails/pull/28111#issuecomment-285370954:

We already call prepare a thoroughly variable number of times -- if your prepare handler isn't idempotent, you're going to have a bad time.

So I changed the classes used in Redmine::Preparation to be idempotent. Please see the attached patch.

Now reloading works:

Reloading...
=> true

Best regards,
Thomas


Files

Actions #1

Updated by Go MAEDA about 1 year ago

  • Tracker changed from Patch to Defect
  • Status changed from New to Confirmed
Actions #2

Updated by Mischa The Evil about 1 year ago

I've had a quick look at the attached patch file (didn't test it though). It seems to also change/break some features too, namely:
  • Feature #14008 (Add a warning if 2 plugins have the same settings partial name);
  • Protection against registering multiple wiki formatters with the same name.

This should be tested carefully before it is being committed.

Actions #3

Updated by Thomas Löber about 1 year ago

You are absolutely right. I have added an updated patch. (I am not allowed to delete the first patch, though.)

Actions #4

Updated by Go MAEDA about 2 months ago

  • Target version set to 6.0.0

Setting the target version to 6.0.0.

Actions #5

Updated by Go MAEDA 15 days ago

  • Subject changed from Redmine 5: RuntimeError when reloading Rails console to RuntimeError when reloading Rails console
  • Category set to Rails support
  • Status changed from Confirmed to Closed
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the patch in r22681. Thank you.

Actions

Also available in: Atom PDF