https://www.redmine.org/https://www.redmine.org/favicon.ico?16793021292023-02-23T19:22:32ZRedmineRedmine - Defect #38286: "Cannot delete enumeration" error may occur when attempting to delete a project with time entrieshttps://www.redmine.org/issues/38286?journal_id=1093722023-02-23T19:22:32ZHolger Just
<ul></ul><p>When destroying a project, Redmine recursively destroys all related objects.</p>
<p>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.</p>
<p>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.</p>
<p>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 <code>time_entry_activities</code> below the declaration of the <code>time_entries</code>:</p>
<pre><code class="diff syntaxhl"><span class="gd">--- a/app/models/project.rb
</span><span class="gi">+++ b/app/models/project.rb
</span><span class="p">@@ -30,8 +30,6 @@</span> class Project < ActiveRecord::Base
# Maximum length for project identifiers
IDENTIFIER_MAX_LENGTH = 100
- # Specific overridden Activities
<span class="gd">- has_many :time_entry_activities, :dependent => :destroy
</span> has_many :memberships, :class_name => 'Member', :inverse_of => :project
# Memberships of active users only
has_many :members,
<span class="p">@@ -44,6 +42,8 @@</span> 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
<span class="gi">+ # Specific overridden Activities
+ has_many :time_entry_activities, :dependent => :destroy
</span> has_many :queries, :dependent => :destroy
has_many :documents, :dependent => :destroy
has_many :news, lambda {includes(:author)}, :dependent => :destroy
</code></pre> Redmine - Defect #38286: "Cannot delete enumeration" error may occur when attempting to delete a project with time entrieshttps://www.redmine.org/issues/38286?journal_id=1093732023-02-23T19:59:05ZHolger Just
<ul><li><strong>Status</strong> changed from <i>New</i> to <i>Confirmed</i></li></ul> Redmine - Defect #38286: "Cannot delete enumeration" error may occur when attempting to delete a project with time entrieshttps://www.redmine.org/issues/38286?journal_id=1094212023-03-01T14:13:54ZGo MAEDA
<ul><li><strong>Related to</strong> <i><a class="issue tracker-3 status-5 priority-4 priority-default closed" href="/issues/36416">Patch #36416</a>: Cleanup more dependent objects on project delete</i> added</li></ul> Redmine - Defect #38286: "Cannot delete enumeration" error may occur when attempting to delete a project with time entrieshttps://www.redmine.org/issues/38286?journal_id=1094242023-03-02T04:04:39ZGo MAEDA
<ul><li><strong>Target version</strong> set to <i>Candidate for next minor release</i></li></ul> Redmine - Defect #38286: "Cannot delete enumeration" error may occur when attempting to delete a project with time entrieshttps://www.redmine.org/issues/38286?journal_id=1094282023-03-02T08:38:27ZMizuki ISHIKAWA
<ul></ul><p>If you change the test code as follows, you will see that the test fails before the <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Defect: "Cannot delete enumeration" error may occur when attempting to delete a project with time entries (Closed)" href="https://www.redmine.org/issues/38286#note-1">#38286#note-1</a> change and succeeds after the change.</p>
<pre><code class="diff syntaxhl"><span class="gh">diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb
index 3e478e66ee..a27da8f9de 100644
</span><span class="gd">--- a/test/unit/project_test.rb
</span><span class="gi">+++ b/test/unit/project_test.rb
</span><span class="p">@@ -236,6 +236,7 @@</span> class ProjectTest < ActiveSupport::TestCase
# generate some dependent objects
overridden_activity = TimeEntryActivity.new({:name => "Project", :project => @ecookbook})
assert overridden_activity.save!
<span class="gi">+ TimeEntry.generate!(:project => @ecookbook, :activity_id => overridden_activity.id)
</span>
query = IssueQuery.generate!(:project => @ecookbook, :visibility => Query::VISIBILITY_ROLES, :roles => Role.where(:id => [1, 3]).to_a)
</code></pre> Redmine - Defect #38286: "Cannot delete enumeration" error may occur when attempting to delete a project with time entrieshttps://www.redmine.org/issues/38286?journal_id=1095002023-03-13T02:40:52ZGo MAEDA
<ul><li><strong>Target version</strong> changed from <i>Candidate for next minor release</i> to <i>5.0.6</i></li></ul><p>Setting the target version to 5.0.6.</p> Redmine - Defect #38286: "Cannot delete enumeration" error may occur when attempting to delete a project with time entrieshttps://www.redmine.org/issues/38286?journal_id=1095722023-03-25T05:10:10ZGo MAEDA
<ul><li><strong>Status</strong> changed from <i>Confirmed</i> to <i>Resolved</i></li><li><strong>Assignee</strong> set to <i>Go MAEDA</i></li><li><strong>Resolution</strong> set to <i>Fixed</i></li></ul><p>Committed the fix. Thank you.</p> Redmine - Defect #38286: "Cannot delete enumeration" error may occur when attempting to delete a project with time entrieshttps://www.redmine.org/issues/38286?journal_id=1095742023-03-25T23:50:28ZGo MAEDA
<ul><li><strong>Subject</strong> changed from <i>Cannot delete project (raise "Cannot delete enumeration")</i> to <i>"Cannot delete enumeration" error may occur when attempting to delete a project with time entries</i></li><li><strong>Status</strong> changed from <i>Resolved</i> to <i>Closed</i></li></ul> Redmine - Defect #38286: "Cannot delete enumeration" error may occur when attempting to delete a project with time entrieshttps://www.redmine.org/issues/38286?journal_id=1101532023-06-02T05:15:58ZGo MAEDA
<ul><li><strong>Has duplicate</strong> <i><a class="issue tracker-3 status-5 priority-4 priority-default closed" href="/issues/38645">Patch #38645</a>: RuntimeError when calling Project#destroy with overridden activity time entry</i> added</li></ul>