Defect #36940

Chained custom field filter doesn't work for User fields

Added by Thomas Löber 6 months ago. Updated 3 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Marius BALTEANU% Done:

0%

Category:Filters
Target version:4.2.8
Resolution:Fixed Affected version:4.2.5

Description

A chained custom field filter doesn't work for fields with format User.

Steps to reproduce:

  1. Create a user custom field A (the format doesn't matter) and check Used as a filter
  2. Create an issue custom field B with format User and check Used as a filter
  3. On the My account page set the custom value A for your own account to an arbitrary value
  4. Create an issue and select <<me>> for the custom field B
  5. Filter the issue list by the filter B's A and use the value you set on the My account page
Expected result:
  • The issue is found
Actual result:
  • The issue is not found

The reason is that the SQL that filters the issues contains a WHERE customized_type='User'. However, the correct clause would be WHERE customized_type='Principal'.

Here is a patch to fix the issue:

--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -1166,7 +1166,7 @@ class Query < ActiveRecord::Base
     end

     filter = available_filters[field]
-    target_class = filter[:through].format.target_class
+    target_class = filter[:through].format.target_class.base_class

     "#{queried_table_name}.id #{not_in} IN (" +
       "SELECT customized_id FROM #{CustomValue.table_name}" +

Best regards,
Thomas

0001-Fix-chained-custom-field-filter-doesn-t-work-for-Use.patch Magnifier (2.04 KB) Marius BALTEANU, 2022-06-25 21:23

Associated revisions

Revision 21686
Added by Marius BALTEANU 3 months ago

Fix chained custom field filter doesn't work for User fields (#36940).

Patch by Thomas Löber.

Revision 21687
Added by Marius BALTEANU 3 months ago

Add test for #37349.

Revision 21690
Added by Marius BALTEANU 3 months ago

Merged r21686 and r21687 to 5.0-stable (#36940).

Revision 21691
Added by Marius BALTEANU 3 months ago

Merged r21686 and r21687 to 4.2-stable (#36940).

History

#1 Updated by Go MAEDA 5 months ago

  • Status changed from New to Confirmed

#2 Updated by Go MAEDA 5 months ago

  • Target version set to Candidate for next minor release

#3 Updated by Marius BALTEANU 3 months ago

I'm not sure if we should that change for all classes, maybe we will break some plugins.

What do you think about the attached change?

#4 Updated by Thomas Löber 3 months ago

I don't think it's necessary to differentiate between User and other classes.

base_class is an ActiveRecord class method and returns exactly the class, whose name is stored in the customized_type column, i.e. the base model for the STI models, if any:

User.base_class => Principal
Issue.base_class => Issue

#5 Updated by Marius BALTEANU 3 months ago

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

I thought that maybe some plugins developers will add some custom fields that extend a base class and they don't want to filter after the base class.

#6 Updated by Marius BALTEANU 3 months ago

  • Status changed from Confirmed to Resolved
  • Assignee set to Marius BALTEANU
  • Resolution set to Fixed

Patch posted by Thomas committed with a test.

#7 Updated by Marius BALTEANU 3 months ago

Test committed in r21687 is for this issue, not for #37349.

#8 Updated by Marius BALTEANU 3 months ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF