Patch #25265

QueriesController can not handle subclass of IssueQuery

Added by Haihan Ji 8 months ago. Updated 8 months ago.

Status:NewStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Issues filter
Target version:-

Description

I have a PivotQuery, it's a subclass of IssueQuery.
But Query don't think it is subclass of himself.
So, r15635 let my plugin down.

I changed QueriesController to fix it.

OLD CODE:

def query_class
  Query.get_subclass(params[:type] || 'IssueQuery')
end

New Code
def query_class
  get_query_class(params[:type] || 'IssueQuery')
end

def get_query_class(class_name)
  klass = nil
  begin
    klass = class_name.to_s.classify.constantize
  rescue
    # invalid class name
  end
  unless klass && klass.new.is_a?(Query)
    klass = nil
  end
  klass    
end

History

#1 Updated by Haihan Ji 8 months ago

Maybe klass < Query is better than klass && klass.new.is_a?(Query).

#2 Updated by Jean-Philippe Lang 8 months ago

We should be able to fix get_subclass instead:

Index: lib/redmine/subclass_factory.rb
===================================================================
--- lib/redmine/subclass_factory.rb    (revision 16379)
+++ lib/redmine/subclass_factory.rb    (working copy)
@@ -29,7 +29,7 @@
         rescue
           # invalid class name
         end
-        unless subclasses.include? klass
+        unless descendants.include? klass
           klass = nil
         end
         klass

Would it work for you?

Also available in: Atom PDF