Defect #38286
closed"Cannot delete enumeration" error may occur when attempting to delete a project with time entries
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 almost 2 years 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 almost 2 years ago
- Related to Patch #36416: Cleanup more dependent objects on project delete added
Updated by Go MAEDA almost 2 years ago
- Target version set to Candidate for next minor release
Updated by Mizuki ISHIKAWA almost 2 years 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)
Updated by Go MAEDA almost 2 years ago
- Target version changed from Candidate for next minor release to 5.0.6
Setting the target version to 5.0.6.
Updated by Go MAEDA almost 2 years ago
- Status changed from Confirmed to Resolved
- Assignee set to Go MAEDA
- Resolution set to Fixed
Committed the fix. Thank you.
Updated by Go MAEDA almost 2 years ago
- Subject changed from Cannot delete project (raise "Cannot delete enumeration") to "Cannot delete enumeration" error may occur when attempting to delete a project with time entries
- Status changed from Resolved to Closed
Updated by Go MAEDA over 1 year ago
- Has duplicate Patch #38645: RuntimeError when calling Project#destroy with overridden activity time entry added