Project

General

Profile

Actions

Defect #38286

closed

"Cannot delete enumeration" error may occur when attempting to delete a project with time entries

Added by naoki takaesu almost 2 years ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Projects
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

Steps to reproduce

  1. Create Project
  2. Settings > Time tracking
    1. uncheck item -> save
    2. check item -> save (System Activity was unchecked)
  3. Click "Spent time" tab
    1. create new log time. (select activity on above item)
  4. Settings > Time tracking
    1. uncheck item -> save
  5. Delete project

It is displayed 500 internal server error.
(raise "Cannot delete enumeration")


Related issues

Related to Redmine - Patch #36416: Cleanup more dependent objects on project deleteClosedMarius BÄ‚LTEANU

Actions
Has duplicate Redmine - Patch #38645: RuntimeError when calling Project#destroy with overridden activity time entryClosed

Actions
Actions #1

Updated by Holger Just over 1 year 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
Actions #2

Updated by Holger Just over 1 year ago

  • Status changed from New to Confirmed
Actions #3

Updated by Go MAEDA over 1 year ago

  • Related to Patch #36416: Cleanup more dependent objects on project delete added
Actions #4

Updated by Go MAEDA over 1 year ago

  • Target version set to Candidate for next minor release
Actions #5

Updated by Mizuki ISHIKAWA over 1 year 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)
Actions #6

Updated by Go MAEDA over 1 year ago

  • Target version changed from Candidate for next minor release to 5.0.6

Setting the target version to 5.0.6.

Actions #7

Updated by Go MAEDA over 1 year ago

  • Status changed from Confirmed to Resolved
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the fix. Thank you.

Actions #8

Updated by Go MAEDA over 1 year 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
Actions #9

Updated by Go MAEDA over 1 year ago

  • Has duplicate Patch #38645: RuntimeError when calling Project#destroy with overridden activity time entry added
Actions

Also available in: Atom PDF