Vote #78974
完了Same relates relation can be created twice
0%
説明
By switching from and to, it is possible to create the same relates relation twice. Within the Redmine UI, those relations look like duplicates.
For all other relationship types it's not allowed to create duplicates, so I assume that this is a bug. Attached you may find a proposed fix. It adds a validation to make sure, that reverse relations are detected. It also orders the from and to IDs to ensure, that even during concurrent access, the duplicates are detected on DB level.
journals
I confirmed the problem.
!{width: 718px; border: 1px solid #ccc;}.duplicated-related-issue@2x.png!
<pre>
sqlite> select * from issue_relations where issue_from_id in (42, 43);
id issue_from_id issue_to_id relation_type delay
---------- ------------- ----------- ------------- ----------
5 42 43 relates
4 43 42 relates
</pre>
--------------------------------------------------------------------------------
LGTM. Setting target version to 3.3.6.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
The patch breaks a test.
<pre>
$ bin/rails test test/functional/issue_relations_controller_test.rb
Run options: --seed 33551
# Running:
...F
Failure:
IssueRelationsControllerTest#test_create_xhr [/Users/maeda/redmines/redmine-trunk/test/functional/issue_relations_controller_test.rb:85]:
Expected: 3
Actual: 1
bin/rails test test/functional/issue_relations_controller_test.rb:70
........
Finished in 4.495535s, 2.6693 runs/s, 6.6733 assertions/s.
12 runs, 30 assertions, 1 failures, 0 errors, 0 skips
</pre>
--------------------------------------------------------------------------------
Fix for the test failure described in #27663#note-4.
@issue_from_id@ is always smaller than @issue_to_id@ after applying the patch.
<pre><code class="diff">
Index: test/functional/issue_relations_controller_test.rb
===================================================================
--- test/functional/issue_relations_controller_test.rb (revision 17054)
+++ test/functional/issue_relations_controller_test.rb (working copy)
@@ -82,8 +82,8 @@
assert_equal 'text/javascript', response.content_type
end
relation = IssueRelation.order('id DESC').first
- assert_equal 3, relation.issue_from_id
- assert_equal 1, relation.issue_to_id
+ assert_equal 1, relation.issue_from_id
+ assert_equal 3, relation.issue_to_id
assert_include 'Bug #1', response.body
end
</code></pre>
--------------------------------------------------------------------------------
Committed in the trunk and merged to stable branches. Thank you.
--------------------------------------------------------------------------------
Thanks a lot.
I am very sorry for breaking the test suite. I hope this did not cause too much trouble. I'll make sure to run the whole test suite next time.
--------------------------------------------------------------------------------