View Issue Details

IDProjectCategoryView StatusLast Update
0026621mantisbtfilterspublic2020-03-15 15:23
ReporterTomekAP Assigned Tocproensa  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Product Version2.23.0 
Target Version2.24.0Fixed in Version2.24.0 
Summary0026621: Wrong filtering by none-relationship
Description

If you choose in filter relationship: "none to a bug " SQL is written in a wrong way.
It rather should be with NOT EXISTS, than with Joins to relationship table with COALESCE conditions.
So is:
$t_where = 'NOT COALESCE(' . $t_table_dst . '.source_bug_id, -1) = ' . $this->param( $c_rel_bug )
. ' AND NOT COALESCE(' . $t_table_src . '.destination_bug_id, -1) = ' . $this->param( $c_rel_bug )
. ' AND NOT {bug}.id = ' . $this->param( $c_rel_bug );
Should be:

            $t_where = 'NOT EXISTS( SELECT 1 FROM {bug_relationship} WHERE source_bug_id = ' . $this->param( $c_rel_bug ) . ' AND destination_bug_id = {bug}.id'
                    . ' OR destination_bug_id = ' . $this->param( $c_rel_bug ) . ' AND source_bug_id = {bug}.id)';

Is:
$this->add_join( 'LEFT JOIN {bug_relationship} ' . $t_table_dst . ' ON ' . $t_table_dst . '.destination_bug_id = {bug}.id' );
$this->add_join( 'LEFT JOIN {bug_relationship} ' . $t_table_src . ' ON ' . $t_table_src . '.source_bug_id = {bug}.id' );
Should be:
if( BUG_REL_NONE != $c_rel_type || (META_FILTER_NONE == $c_rel_bug || META_FILTER_ANY == $c_rel_bug) ) {
$this->add_join( 'LEFT JOIN {bug_relationship} ' . $t_table_dst . ' ON ' . $t_table_dst . '.destination_bug_id = {bug}.id' );
$this->add_join( 'LEFT JOIN {bug_relationship} ' . $t_table_src . ' ON ' . $t_table_src . '.source_bug_id = {bug}.id' );
}

Example:
if bug A has relationship to B and C and you choose none relationship to B, A would be chosen, because of existing non-B = C relationship.
In NOT EXISTS A wouldn`t be chosen

TagsNo tags attached.

Activities

cproensa

cproensa

2020-01-23 19:32

developer   ~0063505

This is the fix based on your proposal.
Please have a look to see if it's ok
PR: https://github.com/mantisbt/mantisbt/pull/1615

TomekAP

TomekAP

2020-01-24 02:25

reporter   ~0063507

I am OK with it.

Related Changesets

MantisBT: master 83a0e56c

2020-01-23 14:23

cproensa

Committer: dregad


Details Diff
Fix filter by relationship

Fix scenario when filtering by "none" relation to a given issue id.

Fixes: 26621
Affected Issues
0026621
mod - core/classes/BugFilterQuery.class.php Diff File