https://www.redmine.org/https://www.redmine.org/favicon.ico?16793021292020-10-13T07:14:54ZRedmineRedmine - Defect #34108: "Is duplicate of" and "Has duplicate" issue relations can be a circular referencehttps://www.redmine.org/issues/34108?journal_id=994082020-10-13T07:14:54ZYuichi HARADA
<ul><li><strong>File</strong> <a href="/attachments/26069">fixed-34108.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/26069/fixed-34108.patch">fixed-34108.patch</a> added</li></ul><p>I made the following patch with reference to the modification of <a class="issue tracker-3 status-5 priority-4 priority-default closed" title="Patch: Same relates relation can be created twice (Closed)" href="https://www.redmine.org/issues/27663">#27663</a> .</p>
<pre><code class="diff syntaxhl"><span class="gh">diff --git a/app/models/issue_relation.rb b/app/models/issue_relation.rb
index d0a66ba40..e0075cb0a 100644
</span><span class="gd">--- a/app/models/issue_relation.rb
</span><span class="gi">+++ b/app/models/issue_relation.rb
</span><span class="p">@@ -239,6 +239,10 @@</span> class IssueRelation < ActiveRecord::Base
issue_from.blocks? issue_to
when 'blocks'
issue_to.blocks? issue_from
<span class="gi">+ when 'duplicated'
+ self.class.where(issue_from_id: issue_from, issue_to_id: issue_to, relation_type: TYPE_DUPLICATES).exists?
+ when 'duplicates'
+ self.class.where(issue_from_id: issue_to, issue_to_id: issue_from, relation_type: TYPE_DUPLICATES).exists?
</span> when 'relates'
self.class.where(issue_from_id: issue_to, issue_to_id: issue_from).present?
else
</code></pre> Redmine - Defect #34108: "Is duplicate of" and "Has duplicate" issue relations can be a circular referencehttps://www.redmine.org/issues/34108?journal_id=994102020-10-14T05:49:31ZYuichi HARADA
<ul><li><strong>File</strong> <a href="/attachments/26072">fixed-34108-v2.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/26072/fixed-34108-v2.patch">fixed-34108-v2.patch</a> added</li></ul><p>The registration data may contain Issues that you have already circular dependency. To solve this, add the following patch to <a class="attachment" href="https://www.redmine.org/attachments/26069">fixed-34108.patch</a> .</p>
<pre><code class="diff syntaxhl"><span class="gh">diff --git a/app/models/issue.rb b/app/models/issue.rb
index 8c3146137..21aed394b 100644
</span><span class="gd">--- a/app/models/issue.rb
</span><span class="gi">+++ b/app/models/issue.rb
</span><span class="p">@@ -1848,6 +1848,14 @@</span> class Issue < ActiveRecord::Base
# Closes duplicates if the issue is being closed
def close_duplicates
if Setting.close_duplicate_issues? && closing?
<span class="gi">+ # Check that there are no circular dependency of relationships
+ relations_to.where(:relation_type => IssueRelation::TYPE_DUPLICATES).each do |relation|
+ unless relation.valid?
+ errors.add :base, relation.errors.full_messages.first
+ throw :abort
+ end
+ end
+
</span> duplicates.each do |duplicate|
# Reload is needed in case the duplicate was updated by a previous duplicate
duplicate.reload
</code></pre> Redmine - Defect #34108: "Is duplicate of" and "Has duplicate" issue relations can be a circular referencehttps://www.redmine.org/issues/34108?journal_id=994232020-10-15T14:07:52ZGo MAEDA
<ul><li><strong>Target version</strong> set to <i>Candidate for next minor release</i></li></ul> Redmine - Defect #34108: "Is duplicate of" and "Has duplicate" issue relations can be a circular referencehttps://www.redmine.org/issues/34108?journal_id=1002522020-12-20T09:32:31ZGo MAEDA
<ul></ul><p>Yuichi HARADA wrote:</p>
<blockquote>
<p>I made the following patch with reference to the modification of <a class="issue tracker-3 status-5 priority-4 priority-default closed" title="Patch: Same relates relation can be created twice (Closed)" href="https://www.redmine.org/issues/27663">#27663</a> .</p>
<p>[...]</p>
</blockquote>
<p>Thank you for writing the patch. But I found that <a class="attachment" href="https://www.redmine.org/attachments/26072">fixed-34108-v2.patch</a> does not cover the situation that 3 or more issues make circular dependency.</p>
<ul>
<li>Issue 101 ---(has duplicate)---> Issue 102</li>
<li>Issue 102 ---(has duplicate)---> Issue 103</li>
<li>Issue 103 ---(has duplicate)---> Issue 101</li>
</ul> Redmine - Defect #34108: "Is duplicate of" and "Has duplicate" issue relations can be a circular referencehttps://www.redmine.org/issues/34108?journal_id=1002762020-12-23T02:57:05ZYuichi HARADA
<ul><li><strong>File</strong> <a href="/attachments/26460">fixed-34108-v3.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/26460/fixed-34108-v3.patch">fixed-34108-v3.patch</a> added</li></ul><p>Go MAEDA wrote:</p>
<blockquote>
<p>Thank you for writing the patch. But I found that <a class="attachment" href="https://www.redmine.org/attachments/26072">fixed-34108-v2.patch</a> does not cover the situation that 3 or more issues make circular dependency.</p>
<ul>
<li>Issue 101 ---(has duplicate)---> Issue 102</li>
<li>Issue 102 ---(has duplicate)---> Issue 103</li>
<li>Issue 103 ---(has duplicate)---> Issue 101</li>
</ul>
</blockquote>
<p>Thank you for pointing this out. I have fixed it to cover situations where three or more issues cause circular dependencies.</p>
<pre><code class="diff syntaxhl"><span class="gh">diff --git a/app/models/issue.rb b/app/models/issue.rb
index 8ba261bb1f..a8810611cb 100644
</span><span class="gd">--- a/app/models/issue.rb
</span><span class="gi">+++ b/app/models/issue.rb
</span><span class="p">@@ -1930,6 +1930,13 @@</span> class Issue < ActiveRecord::Base
# Closes duplicates if the issue is being closed
def close_duplicates
if Setting.close_duplicate_issues? && closing?
<span class="gi">+ # Check that there are no circular dependency of relationships
+ duplicate_issue_ids = circular_dependency_duplicate_issue_ids(duplicates)
+ if duplicate_issue_ids.include?(self.id)
+ self.errors.add :base, :circular_dependency
+ throw :abort
+ end
+
</span> duplicates.each do |duplicate|
# Reload is needed in case the duplicate was updated by a previous duplicate
duplicate.reload
<span class="p">@@ -1946,6 +1953,17 @@</span> class Issue < ActiveRecord::Base
end
end
+ def circular_dependency_duplicate_issue_ids(issues, duplicate_ids = [])
<span class="gi">+ issues.each do |issue|
+ next if duplicate_ids.include?(issue.id)
+
+ duplicate_ids << issue.id
+ duplicate_ids.concat(circular_dependency_duplicate_issue_ids(issue.duplicates, duplicate_ids))
+ duplicate_ids.uniq!
+ end
+ duplicate_ids
+ end
+
</span> # Make sure updated_on is updated when adding a note and set updated_on now
# so we can set closed_on with the same value on closing
def force_updated_on_change
</code></pre>