Defect #39803
openPlugin modules no longer working
Added by Guus Teley 12 months ago. Updated 11 months ago.
0%
Description
Debugging lib/redmine/plugin_loader.rb shows that in
add_autoload_paths
in engine_cfg.all_eager_load_paths.each do |dir|
the following directories are added:
- app/controllers
- app/helpers
- app/models
- lib
Note that the lib directory also has been added before with an explicit engine_cfg.paths.add 'lib', eager_load: true
Trying to force load the required module with require File.expand_path('../lib/my_module', __FILE__)
or require_relative 'lib/my_module'
doesn't help.
Before migrating to Rails 7, a simple require MyModule
worked fine.
Files
init.rb (2.71 KB) init.rb | Guus Teley, 2023-12-12 15:15 | ||
itgn_module.rb (1.21 KB) itgn_module.rb | Guus Teley, 2023-12-12 15:15 | ||
39803.patch (3.31 KB) 39803.patch | Marius BĂLTEANU, 2023-12-17 04:46 |
Related issues
Updated by Marius BĂLTEANU 12 months ago
- Related to Feature #36320: Migrate to Rails 7.2 added
Updated by Marius BĂLTEANU 12 months ago
- Status changed from New to Needs feedback
Updated by Guus Teley 12 months ago
Hello Marius,
You're correct. I seem to have the 5.1.1-devel version installed which pulled Rails 7.1.2 with it.
Does this mean the support of plugins has fundamentally changed or should there come some updates so that plugins are working again as before?
Updated by Marius BĂLTEANU 12 months ago
There were some changes, but it should work as before.
Can you try with the latest version of trunk (r22514)? all the tests finally pass now. If still doesn't work, please provide the steps to reproduce the problem.
Updated by Takashi Kato 12 months ago
Hello Guus.
From Redmine 5.0, plugin modules are loaded automatically by the Ruby on Rails autoloader. It's important for the autoloader to match both the Ruby file name and class name, as detailed in the Rails Guide
Potential reasons for a plugin not working might include:
- Mismatch between class names and file names
- RAILS_ENV being set to test (a recent commit changed the directory for plugin lookup based on RAILS_ENV)
I've developed a sample plugin that functions with the current Redmine trunk, and you can find it here.
https://github.com/tohosaku/redmine_simple_example/tree/master
To test it:
- Clone the repository into the plugins directory.
- Run the following command in the terminal:
RAILS_ENV=development bin/rails s
. - Access localhost:3000/example in your browser.
Try accessing the pages with "hello" and "Hello fuga."
If you can view both pages successfully, it indicates that both the autoloader and the module loaded by require_relative are working as intended.
Updated by Alexander Meindl 12 months ago
Marius BALTEANU wrote in #note-5:
There were some changes, but it should work as before.
Hi,
our plugins to not work as before, see e.g. https://github.com/alphanodes/redmine_ref_issues/actions/runs/7167043514. All tests with master / Rails 7.1 are broken.
E.g.:
Run bundle exec rake redmine:plugins:test NAME=redmine_ref_issues RUBYOPT="-W0" rake aborted! NoMethodError: undefined method `rake_run' for Rails::TestUnit::Runner:Class (NoMethodError) Rails::TestUnit::Runner.rake_run ["plugins/#{ENV['NAME'] || '*'}/test/unit/**/*_test.rb"] ^^^^^^^^^ /home/runner/work/redmine_ref_issues/redmine_ref_issues/redmine/lib/tasks/redmine.rake:182:in `block (4 levels) in <top (required)>' /home/runner/work/redmine_ref_issues/redmine_ref_issues/redmine/lib/tasks/redmine.rake:172:in `block (3 levels) in <top (required)>' /opt/hostedtoolcache/Ruby/3.2.2/x64/bin/bundle:25:in `load' /opt/hostedtoolcache/Ruby/3.2.2/x64/bin/bundle:25:in `<main>' Tasks: TOP => redmine:plugins:test:units (See full trace by running task with --trace) Error: Process completed with exit code 1.
In https://github.com/alphanodes/additionals/actions/runs/7166976930/job/19512117928 this error:
Run bundle exec rake generate_secret_token rake aborted! NameError: uninitialized constant Additionals::Patches Did you mean? Pathname /home/runner/work/additionals/additionals/redmine/plugins/additionals/init.rb:52:in `block in <top (required)>' /home/runner/work/additionals/additionals/redmine/plugins/additionals/init.rb:51:in `<top (required)>' /home/runner/work/additionals/additionals/redmine/plugins/additionals/lib/additionals.rb:186:in `block in <class:Plugin>' /home/runner/work/additionals/additionals/redmine/config/environment.rb:16:in `<top (required)>' /opt/hostedtoolcache/Ruby/3.0.6/x64/bin/bundle:23:in `load' /opt/hostedtoolcache/Ruby/3.0.6/x64/bin/bundle:23:in `<main>' Tasks: TOP => db:create => db:load_config => environment (See full trace by running task with --trace)
Looks like lib
directory of a plugin is not found.
Updated by Guus Teley 12 months ago
This works (I get an form showing "Hello" and "Hello fuga"
But trying to get my own plugin to work fails with the program being unable to find the methods in the library module.
I saw you named your Module 'class' in hoge.rb and 'module' plus 'class' in redmine_simple_example.rb.
It's a mystery to me why I now all of a sudden have to explicitly specify the module/class name with every call to my methods.
Is that something new with 7.1?
Updated by Marius BĂLTEANU 12 months ago
Alexander Meindl wrote in #note-7:
Marius BALTEANU wrote in #note-5:
There were some changes, but it should work as before.
Hi,
our plugins to not work as before, see e.g. https://github.com/alphanodes/redmine_ref_issues/actions/runs/7167043514. All tests with master / Rails 7.1 are broken.
E.g.:
[...]
In https://github.com/alphanodes/additionals/actions/runs/7166976930/job/19512117928 this error:
[...]
Looks like
lib
directory of a plugin is not found.
Method rake_run
was removed in Rails 7, we will properly fix this issue.
Also, there is another issue introduced by r22507 which changes the plugins directory for testing environment to another folder in order to test the autoloading and I'm not sure if we should revert this change or each plugin should set in their config environment the line config.redmine_plugin_directory = 'plugins'
.
What do you think?
Updated by Takashi Kato 12 months ago
Guus Teley wrote in #note-8:
This works (I get an form showing "Hello" and "Hello fuga"
But trying to get my own plugin to work fails with the program being unable to find the methods in the library module.
I saw you named your Module 'class' in hoge.rb and 'module' plus 'class' in redmine_simple_example.rb.
It's a mystery to me why I now all of a sudden have to explicitly specify the module/class name with every call to my methods.
Is that something new with 7.1?
If all is well, can you upload your plugin?
If you can remove the parts you don't think are necessary for the survey and leave us with at least two files, init.rb and the unloaded module, we can investigate how it is working.
Updated by Alexander Meindl 12 months ago
Marius BALTEANU wrote in #note-9:
[...]
Method
rake_run
was removed in Rails 7, we will properly fix this issue.Also, there is another issue introduced by r22507 which changes the plugins directory for testing environment to another folder in order to test the autoloading and I'm not sure if we should revert this change or each plugin should set in their config environment the line
config.redmine_plugin_directory = 'plugins'
.What do you think?
I think, it would be better we do not change redmine_plugin_directory
with config/environments/test.rb for autoloading tests. For this tests we can set the plugin directory in the test file.
In general I think it is a good idea, to make the plugin directory configurable - as it is already commited.
Updated by Takashi Kato 12 months ago
Alexander Meindl wrote in #note-11:
[...]
I think, it would be better we do not change
redmine_plugin_directory
with config/environments/test.rb for autoloading tests. For this tests we can set the plugin directory in the test file.
In general I think it is a good idea, to make the plugin directory configurable - as it is already commited.
I have opened a new issue on plugin testing(#39834).
Updated by Guus Teley 12 months ago
@"Takashi Kato": After installing your example in the development environment I'll noticed everything worked.
Then I noticed the same generated errors when switching back to the production environment.
The error was: "Exception `NameError' at /usr/local/lib/ruby/gems/3.1/gems/zeitwerk-2.6.12/lib/zeitwerk/loader/helpers.rb:135 - uninitialized constant Hoge"
So there's a difference in behaviour between the production and development environment which I'm not aware of.
After changing the config.eager_load value to 'false' for the production environment, everything seems to worked as expected.
It definitely looks like this is the culprit.
Hope this helps.
Updated by Guus Teley 12 months ago
- File init.rb init.rb added
- File itgn_module.rb itgn_module.rb added
As an addition: My methods in my Module still don't work.
Error message: " NoMethodError (undefined method `access_level' for ItgnModule:Module"
I've attached the init.rb and library module.
Updated by Marius BĂLTEANU 12 months ago
Alexander Meindl wrote in #note-11:
Marius BALTEANU wrote in #note-9:
[...]Method
rake_run
was removed in Rails 7, we will properly fix this issue.Also, there is another issue introduced by r22507 which changes the plugins directory for testing environment to another folder in order to test the autoloading and I'm not sure if we should revert this change or each plugin should set in their config environment the line
config.redmine_plugin_directory = 'plugins'
.What do you think?
I think, it would be better we do not change
redmine_plugin_directory
with config/environments/test.rb for autoloading tests. For this tests we can set the plugin directory in the test file.
In general I think it is a good idea, to make the plugin directory configurable - as it is already commited.
I've reverted those changes and I've committed the fix posted by tohosaku for @undefined method `rake_run`
. Can you confirm that your plugins work as before?
Updated by Alexander Meindl 12 months ago
Hi Marius,
it looks good. All tests with master branch runs without problems: https://github.com/alphanodes/additionals/actions/runs/7186533064
This means both works: revert of plugin directory and rake_run fix.
Thanks for the fast work on it!
Updated by Alexander Meindl 11 months ago
I found a side effect with change from Rails::TestUnit::Runner.rake_run
to Rails::TestUnit::Runner.run_from_rake
with revision r22517
If I run rake task redmine:plugins:test
to run all tests of a plugin (unit, functional and integration tests), there starts there new sessions - after each other.
In general the same test helper is used for all tests. For coverage in the helper there can be
require 'simplecov'
SimpleCov.start :rails do
add_filter 'init.rb'
root File.expand_path "#{File.dirname __FILE__}/.."
end
as an example.
Now this code is executed 3 times - for unit tests, than before functional tests and the before integration tests.
See this output as an example:
bundle exec rails redmine:plugins:test RAILS_ENV=test NAME=myplugin Emptying /Users/alex/dev/redmine_master/test/reports Started with run options --seed 23283 Finished in 238.72515s 391 tests, 1601 assertions, 0 failures, 0 errors, 1 skips Emptying /Users/alex/dev/redmine_master/test/reports Started with run options --seed 62191 Finished in 157.84991s 407 tests, 2403 assertions, 0 failures, 0 errors, 0 skips Emptying /Users/alex/dev/redmine_master/test/reports Started with run options --seed 12353 Finished in 78.11091s 110 tests, 706 assertions, 0 failures, 0 errors, 0 skips
The reports cleaned after each test group, which is not correct - because test results are deleted of the test group before.
Updated by Marius BĂLTEANU 11 months ago
- File 39803.patch 39803.patch added
Alexander, the problem is not caused by Redmine, but by the Rails changes. I've wrapped the test run execution in a condition that checks if any file exists in each test directory as an workaround, can you check, please?
Updated by Marius BĂLTEANU 11 months ago
Marius BALTEANU wrote in #note-18:
Alexander, the problem is not caused by Redmine, but by the Rails changes. I've wrapped the test run execution in a condition that checks if any file exists in each test directory as an workaround, can you check, please?
I've fixed the issue using a different approach, please see r22524.
I'm leaving this issue open to get clarify the issue reported by Guus Teley.
Updated by Alexander Meindl 11 months ago
Hi Marius,
your new approach solved my problem. Everything with plugin testing works as before. Thanks for your time on that!