Project

General

Profile

Actions

Defect #33121

closed

IssueQuery not usable from plugins

Added by Stefan Rinkes over 4 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Plugin API
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Duplicate
Affected version:

Description

I'm currently working on updating some plugins for the usage with Redmine 4.1.0.

And noticed I cannot init Redmine while my plugins are already located in plugins-folder.

I stripped it down to an patch for IssueQuery included in the plugin.

Here's a minimal plugin to trigger the issue:

require 'redmine'

module RedmineA
  module IssueQueryPatch
  end

  module ProjectPatch
  end
end

Rails.configuration.to_prepare do
  unless Project.included_modules.include? RedmineA::ProjectPatch
    Project.send(:include, RedmineA::ProjectPatch)
  end

  unless IssueQuery.included_modules.include? RedmineA::IssueQueryPatch
    IssueQuery.send(:include, RedmineA::IssueQueryPatch)
  end
end

Redmine::Plugin.register :redmine_a do
  name 'Redmine Test Plugin'
  author 'Stefan Rinkes'
  description 'To show IssueQuery-Patch failure'
  version '0.0.0'
end

Place this as /usr/src/redmine/plugins/redmine_a/init.rb and try to create a brand new database.

# rake db:create
W, [2020-03-10T14:00:19.875929 #12605]  WARN -- : Creating scope :system. Overwriting existing method Enumeration.system.
W, [2020-03-10T14:00:19.905024 #12605]  WARN -- : Creating scope :sorted. Overwriting existing method Group.sorted.
W, [2020-03-10T14:00:19.949338 #12605]  WARN -- : Creating scope :sorted. Overwriting existing method User.sorted.
rake aborted!
ActiveRecord::NoDatabaseError: Unknown database 'redmine_test'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/mysql2_adapter.rb:26:in `rescue in mysql2_connection'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/mysql2_adapter.rb:12:in `mysql2_connection'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:830:in `new_connection'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:874:in `checkout_new_connection'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:853:in `try_to_checkout_new_connection'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:814:in `acquire_connection'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:538:in `checkout'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:1033:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_handling.rb:90:in `connection'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/model_schema.rb:466:in `load_schema!'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/attributes.rb:234:in `load_schema!'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/attribute_decorators.rb:51:in `load_schema!'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/model_schema.rb:459:in `block in load_schema'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/model_schema.rb:456:in `load_schema'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/model_schema.rb:336:in `columns_hash'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/inheritance.rb:78:in `descends_from_active_record?'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/inheritance.rb:84:in `finder_needs_type_condition?'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/core.rb:287:in `relation'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/scoping/default.rb:34:in `unscoped'
/usr/src/redmine/app/models/user.rb:822:in `anonymous'
/usr/src/redmine/app/models/user.rb:816:in `current'
/usr/src/redmine/app/models/query.rb:91:in `groupable'
/usr/src/redmine/app/models/query.rb:31:in `initialize'
/usr/src/redmine/app/models/issue_query.rb:36:in `new'
/usr/src/redmine/app/models/issue_query.rb:36:in `<class:IssueQuery>'
/usr/src/redmine/app/models/issue_query.rb:20:in `<top (required)>'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:291:in `require'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:291:in `block in require'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:257:in `load_dependency'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:291:in `require'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:378:in `block in require_or_load'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:37:in `block in load_interlock'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies/interlock.rb:14:in `block in loading'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies/interlock.rb:13:in `loading'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:37:in `load_interlock'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:356:in `require_or_load'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:510:in `load_missing_constant'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:195:in `const_missing'
/usr/src/redmine/plugins/redmine_a/init.rb:16:in `block in <top (required)>'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:426:in `instance_exec'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:426:in `block in make_lambda'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:198:in `block (2 levels) in halting'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:606:in `block (2 levels) in default_terminator'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:605:in `catch'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:605:in `block in default_terminator'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:199:in `block in halting'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:513:in `block in invoke_before'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:513:in `each'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:513:in `invoke_before'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:131:in `run_callbacks'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/reloader.rb:89:in `prepare!'
/usr/local/bundle/gems/railties-5.2.4.1/lib/rails/application/finisher.rb:63:in `block in <module:Finisher>'
/usr/local/bundle/gems/railties-5.2.4.1/lib/rails/initializable.rb:32:in `instance_exec'
/usr/local/bundle/gems/railties-5.2.4.1/lib/rails/initializable.rb:32:in `run'
/usr/local/bundle/gems/railties-5.2.4.1/lib/rails/initializable.rb:61:in `block in run_initializers'
/usr/local/bundle/gems/railties-5.2.4.1/lib/rails/initializable.rb:60:in `run_initializers'
/usr/local/bundle/gems/railties-5.2.4.1/lib/rails/application.rb:361:in `initialize!'
/usr/src/redmine/config/environment.rb:16:in `<top (required)>'
/usr/local/bundle/gems/railties-5.2.4.1/lib/rails/application.rb:337:in `require'
/usr/local/bundle/gems/railties-5.2.4.1/lib/rails/application.rb:337:in `require_environment!'
/usr/local/bundle/gems/railties-5.2.4.1/lib/rails/application.rb:520:in `block in run_tasks_blocks'
/usr/local/bundle/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'

Caused by:
Mysql2::Error: Unknown database 'redmine_test'
/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `connect'
/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:90:in `initialize'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/mysql2_adapter.rb:22:in `new'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/mysql2_adapter.rb:22:in `mysql2_connection'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:830:in `new_connection'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:874:in `checkout_new_connection'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:853:in `try_to_checkout_new_connection'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:814:in `acquire_connection'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:538:in `checkout'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:382:in `connection'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:1033:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_handling.rb:118:in `retrieve_connection'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/connection_handling.rb:90:in `connection'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/model_schema.rb:466:in `load_schema!'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/attributes.rb:234:in `load_schema!'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/attribute_decorators.rb:51:in `load_schema!'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/model_schema.rb:459:in `block in load_schema'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/model_schema.rb:456:in `load_schema'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/model_schema.rb:336:in `columns_hash'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/inheritance.rb:78:in `descends_from_active_record?'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/inheritance.rb:84:in `finder_needs_type_condition?'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/core.rb:287:in `relation'
/usr/local/bundle/gems/activerecord-5.2.4.1/lib/active_record/scoping/default.rb:34:in `unscoped'
/usr/src/redmine/app/models/user.rb:822:in `anonymous'
/usr/src/redmine/app/models/user.rb:816:in `current'
/usr/src/redmine/app/models/query.rb:91:in `groupable'
/usr/src/redmine/app/models/query.rb:31:in `initialize'
/usr/src/redmine/app/models/issue_query.rb:36:in `new'
/usr/src/redmine/app/models/issue_query.rb:36:in `<class:IssueQuery>'
/usr/src/redmine/app/models/issue_query.rb:20:in `<top (required)>'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:291:in `require'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:291:in `block in require'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:257:in `load_dependency'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:291:in `require'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:378:in `block in require_or_load'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:37:in `block in load_interlock'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies/interlock.rb:14:in `block in loading'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies/interlock.rb:13:in `loading'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:37:in `load_interlock'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:356:in `require_or_load'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:510:in `load_missing_constant'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:195:in `const_missing'
/usr/src/redmine/plugins/redmine_a/init.rb:16:in `block in <top (required)>'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:426:in `instance_exec'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:426:in `block in make_lambda'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:198:in `block (2 levels) in halting'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:606:in `block (2 levels) in default_terminator'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:605:in `catch'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:605:in `block in default_terminator'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:199:in `block in halting'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:513:in `block in invoke_before'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:513:in `each'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:513:in `invoke_before'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/callbacks.rb:131:in `run_callbacks'
/usr/local/bundle/gems/activesupport-5.2.4.1/lib/active_support/reloader.rb:89:in `prepare!'
/usr/local/bundle/gems/railties-5.2.4.1/lib/rails/application/finisher.rb:63:in `block in <module:Finisher>'
/usr/local/bundle/gems/railties-5.2.4.1/lib/rails/initializable.rb:32:in `instance_exec'
/usr/local/bundle/gems/railties-5.2.4.1/lib/rails/initializable.rb:32:in `run'
/usr/local/bundle/gems/railties-5.2.4.1/lib/rails/initializable.rb:61:in `block in run_initializers'
/usr/local/bundle/gems/railties-5.2.4.1/lib/rails/initializable.rb:60:in `run_initializers'
/usr/local/bundle/gems/railties-5.2.4.1/lib/rails/application.rb:361:in `initialize!'
/usr/src/redmine/config/environment.rb:16:in `<top (required)>'
/usr/local/bundle/gems/railties-5.2.4.1/lib/rails/application.rb:337:in `require'
/usr/local/bundle/gems/railties-5.2.4.1/lib/rails/application.rb:337:in `require_environment!'
/usr/local/bundle/gems/railties-5.2.4.1/lib/rails/application.rb:520:in `block in run_tasks_blocks'
/usr/local/bundle/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
Tasks: TOP => db:create => db:load_config => environment
(See full trace by running task with --trace)

Removing the plugin will let you create the database and works flawlessy once the database is there.


Related issues

Is duplicate of Redmine - Defect #33290: Unnecessary database access when IssueQuery class is definedClosedGo MAEDA

Actions
Actions

Also available in: Atom PDF