Defect #38286
openCannot delete project (raise "Cannot delete enumeration")
0%
Description
Steps to reproduce
- Create Project
- Settings > Time tracking
- uncheck item -> save
- check item -> save (System Activity was unchecked)
- Click "Spent time" tab
- create new log time. (select activity on above item)
- Settings > Time tracking
- uncheck item -> save
- Delete project
It is displayed 500 internal server error.
(raise "Cannot delete enumeration")
Related issues
Updated by Holger Just 29 days ago
When destroying a project, Redmine recursively destroys all related objects.
In this case however, it tries to first destroy the (project-local) time entry activities before it destroys the time entries using those activities. Since destroying an activity is only possible when there are no time entries using it, the project destroy may fail in this case.
I believe this may be solved by making sure that during a project destroy, Redmine first destroys the time entries and only then the activities.
I haven't yet fully tested it, but this issue might be solved with a patch like this where we move the declaration of the related time_entry_activities
below the declaration of the time_entries
:
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -30,8 +30,6 @@ class Project < ActiveRecord::Base
# Maximum length for project identifiers
IDENTIFIER_MAX_LENGTH = 100
- # Specific overridden Activities
- has_many :time_entry_activities, :dependent => :destroy
has_many :memberships, :class_name => 'Member', :inverse_of => :project
# Memberships of active users only
has_many :members,
@@ -44,6 +42,8 @@ class Project < ActiveRecord::Base
belongs_to :default_version, :class_name => 'Version'
belongs_to :default_assigned_to, :class_name => 'Principal'
has_many :time_entries, :dependent => :destroy
+ # Specific overridden Activities
+ has_many :time_entry_activities, :dependent => :destroy
has_many :queries, :dependent => :destroy
has_many :documents, :dependent => :destroy
has_many :news, lambda {includes(:author)}, :dependent => :destroy
Updated by Go MAEDA 23 days ago
- Related to Patch #36416: Cleanup more dependent objects on project delete added
Updated by Mizuki ISHIKAWA 22 days ago
If you change the test code as follows, you will see that the test fails before the #38286#note-1 change and succeeds after the change.
diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb
index 3e478e66ee..a27da8f9de 100644
--- a/test/unit/project_test.rb
+++ b/test/unit/project_test.rb
@@ -236,6 +236,7 @@ class ProjectTest < ActiveSupport::TestCase
# generate some dependent objects
overridden_activity = TimeEntryActivity.new({:name => "Project", :project => @ecookbook})
assert overridden_activity.save!
+ TimeEntry.generate!(:project => @ecookbook, :activity_id => overridden_activity.id)
query = IssueQuery.generate!(:project => @ecookbook, :visibility => Query::VISIBILITY_ROLES, :roles => Role.where(:id => [1, 3]).to_a)