プロジェクト

全般

プロフィール

Vote #80776

完了

Unable to autoload constant Version.table_name if gems uses Version class

Admin Redmine さんが3年以上前に追加. 3年以上前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Gems support_45
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
45
version_id:
162
issue_org_id:
33206
author_id:
29628
assigned_to_id:
332
comments:
6
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

Introduced with r18780 Version.table_name is not available, if a gem package (like "attr_encrypted":https://github.com/attr-encrypted/attr_encrypted) is used with a class named "Version".

At the moment this problem does not exist with Gem packages from Redmine itself, but gems from plugins.

Existing tests are broken, e.g.


bin/rails test test/unit/project_test.rb -n test_move_a_root_project_to_a_project
# Running:

E

Error:
ProjectTest#test_move_a_root_project_to_a_project:
NoMethodError: undefined method `table_name' for AttrEncrypted::Version:Module
    app/models/issue.rb:1739:in `update_versions'
    app/models/issue.rb:1385:in `update_versions_from_hierarchy_change'
    app/models/project.rb:935:in `update_versions_from_hierarchy_change'
    app/models/project.rb:424:in `set_parent!'
    test/unit/project_test.rb:316:in `test_move_a_root_project_to_a_project'

Similar problem was #23269. A better description of the problem with examples are here: https://stackoverflow.com/questions/21115567/autoloading-classes-using-class-self-in-rails

I added a patch for a more solid solution to prevent the problem. It would be great to have this change in Redmine.


journals

I added another version of patch, which uses Rails 5 where.not and Arel::Table. With this solution, no more table name specification is required.

Both solutions work, but second one is more cleaner - but more refactoring.
--------------------------------------------------------------------------------
Steps to reproduce the issue:
<pre>
echo gem \'attr_encrypted\' >> Gemfile.local
bundle install
bin/rails test test/unit/project_test.rb -n test_move_a_root_project_to_a_project
</pre>
--------------------------------------------------------------------------------
I think the first variant should be preferred, see https://github.com/rails/rails/issues/36761
--------------------------------------------------------------------------------
I will commit the former patch, attachment:full_qualified_version_class.patch soon.
--------------------------------------------------------------------------------
Committed the patch. Thank you for reporting and fixing the issue.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

Admin Redmine さんが3年以上前に更新

  • カテゴリGems support_45 にセット
  • 対象バージョン4.1.2_162 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0