Project

General

Profile

Actions

Defect #32546

closed

Issue relations filter lacks "is not"

Added by Alexander Achenbach over 4 years ago. Updated over 4 years ago.

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

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

It seems the "is not" operator was omitted in the :relation definition of query operators.
The actual implementation seems to have it, though.
The attached patch adds the operator to the list (applied to Redmine 4.0.5).


Files

fix-relation-query-ops.patch (403 Bytes) fix-relation-query-ops.patch Alexander Achenbach, 2019-12-02 10:52

Related issues

Related to Redmine - Feature #3265: Filter on issue relationsClosedJean-Philippe Lang2009-04-29

Actions
Actions #1

Updated by Go MAEDA over 4 years ago

  • Target version set to Candidate for next major release

Alexander Achenbach wrote:

The actual implementation seems to have it, though.

The implementation for "is not" operator is at source:tags/4.0.5/app/models/issue_query.rb#L568. I think "!" operator was not included by mistake and this should be fixed.

      when "=", "!" 
        op = (operator == "=" ? 'IN' : 'NOT IN')
        "#{Issue.table_name}.id #{op} (SELECT DISTINCT #{IssueRelation.table_name}.#{join_column} FROM #{IssueRelation.table_name} WHERE #{IssueRelation.table_name}.relation_type = '#{self.class.connection.quote_string(relation_type)}' AND #{IssueRelation.table_name}.#{target_join_column} = #{value.first.to_i})" 
Actions #2

Updated by Go MAEDA over 4 years ago

Actions #3

Updated by Go MAEDA over 4 years ago

  • Target version changed from Candidate for next major release to Candidate for next minor release
Actions #4

Updated by Go MAEDA over 4 years ago

Go MAEDA wrote:

The implementation for "is not" operator is at source:tags/4.0.5/app/models/issue_query.rb#L568. I think "!" operator was not included by mistake and this should be fixed.

I started to wonder whether the "is not" filter is practical.

The reason is that the "is not" filter returns too many results. In many cases, it returns almost all issues in the project.

Suppose that there are 1000 issues in the project, and issue 2 and issue 3 have a "related to" relationship with each other. if you apply the filter "Related to" "is not" "3", it returns 999 issues other than issue 2.

I think the result is not so useful.

Actions #5

Updated by Go MAEDA over 4 years ago

Go MAEDA wrote:

I started to wonder whether the "is not" filter is practical.

The reason is that the "is not" filter returns too many results. In many cases, it returns almost all issues in the project.

Sorry, I have changed my mind. Please forget what I wrote in #32546#note-4.

Although I wrote "is not" filter is not so useful, it is wrong. It is useful when it is used with the combination with other filters. For example:

  • "Subject" "contains" "awesome feature"
  • "Is duplicate of" "is not" "10"

Suppose that issue 10 is an issue to implement an awesome feature. There are lot of duplicate issues and you want to create "Is duplicte of" relation ship for all those issues. You can find issues without "Is duplicate of" relationship by the above filter.

Actions #6

Updated by Go MAEDA over 4 years ago

Here is a test for the patch.

diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb
index df6c61551..56ec82d14 100644
--- a/test/unit/query_test.rb
+++ b/test/unit/query_test.rb
@@ -1153,6 +1153,10 @@ class QueryTest < ActiveSupport::TestCase
     query = IssueQuery.new(:name => '_')
     query.filters = {"relates" => {:operator => '=', :values => ['2']}}
     assert_equal [1], find_issues_with_query(query).map(&:id).sort
+
+    query = IssueQuery.new(:name => '_')
+    query.filters = {"relates" => {:operator => '!', :values => ['1']}}
+    assert_equal Issue.where.not(:id => [2, 3]).order(:id).ids, find_issues_with_query(query).map(&:id).sort
   end

   def test_filter_on_relations_with_any_issues_in_a_project
Actions #7

Updated by Alexander Achenbach over 4 years ago

Go MAEDA wrote:

It is useful when it is used with the combination with other filters. [...]

Admittedly we have not had a need for this in years of using Redmine, but projects have become somewhat more complex, and now our use case is a pending re-factorization of related issues, so we have to look for issues "related to A, but not related to B" prior to updating their relations.

Thanks for the test.

Actions #8

Updated by Go MAEDA over 4 years ago

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

Setting the target version to 4.2.0.

Actions #9

Updated by Go MAEDA over 4 years ago

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

Committed the patch. Thank you for reporting and fixing the issue.

Actions #10

Updated by Go MAEDA over 4 years ago

  • Target version changed from 4.2.0 to 4.1.0

I propose to merge this small fix into 4.1-stable.

Actions #11

Updated by Go MAEDA over 4 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF