Project

General

Profile

Actions

Defect #30009

closed

Empty sort criteria for issue query gives error

Added by Kumar Abhinav over 5 years ago. Updated over 5 years ago.

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

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

When saving an Issue query,provide the sort criteria like below, i.e leaving the middle one empty.

Save the query.

With the new query loaded,click on apply.

It gives error.

Bug occured on redmine: 3.4.6


Files

sort.PNG (6.54 KB) sort.PNG Kumar Abhinav, 2018-11-22 11:24
0001-Remove-blank-keys-from-sort-criterias.patch (1.46 KB) 0001-Remove-blank-keys-from-sort-criterias.patch Marius BĂLTEANU, 2018-11-25 21:35

Related issues

Related to Redmine - Defect #32737: Duplicate sort keys for issue query cause SQL error with SQL ServerClosedGo MAEDA

Actions
Actions #1

Updated by Go MAEDA over 5 years ago

  • Category set to Issues
  • Status changed from New to Needs feedback

I could not reproduce the problem. Can you see any error regarding this problem in log/production.log ?

Actions #2

Updated by Kumar Abhinav over 5 years ago

It is reproducible on a clean install of Redmine 3.4.6.
After you save the query,make sure the same query is loaded & click apply.

Since the middle criteria for sort is left empty,the to_param method in Redmine::SortCriteria throws "undefined method `+' for nil:NilClass" error.

Actions #3

Updated by Bernhard Rohloff over 5 years ago

I can confirm the defect. It also occurs on the latest trunk.
Switching the query works as expected. As Kumar wrote it only occurs after applying the query a second time.

Actions #4

Updated by Go MAEDA over 5 years ago

  • Status changed from Needs feedback to Confirmed

Kumar Abhinav wrote:

After you save the query,make sure the same query is loaded & click apply.

Yes, I didn't click "Apply" after creating the query. Now I can reproduce the problem.

Actions #5

Updated by Marius BĂLTEANU over 5 years ago

Attached a patch that fixes this problem by removing the blank keys from sort criteria.

Another fix is the below one, but I prefer the first solution.

diff --git a/lib/redmine/sort_criteria.rb b/lib/redmine/sort_criteria.rb
index c89ef03c1..acfcbdb0f 100644
--- a/lib/redmine/sort_criteria.rb
+++ b/lib/redmine/sort_criteria.rb
@@ -32,7 +32,7 @@ module Redmine
     end

     def to_param
-      self.collect {|k,o| k + (o == 'desc' ? ':desc' : '')}.join(',')
+      self.collect {|k,o| k + (o == 'desc' ? ':desc' : '') unless k.nil? }.join(',')
     end

     def to_a

Also, maybe it is a good idea to fix this issue also in the UI by not allowing to select a third sort criteria without selecting the second.

Actions #6

Updated by Marius BĂLTEANU over 5 years ago

  • Subject changed from empty sort criteria for issue query gives error to Empty sort criteria for issue query gives error
Actions #7

Updated by Go MAEDA over 5 years ago

  • Target version changed from Candidate for next minor release to 3.4.7
Actions #8

Updated by Go MAEDA over 5 years ago

  • Status changed from Confirmed to Resolved
  • Assignee set to Go MAEDA
  • Resolution set to Fixed
Actions #9

Updated by Go MAEDA over 5 years ago

  • Status changed from Resolved to Closed

Committed the patch. Thank you for the patch.

Actions #10

Updated by Go MAEDA about 4 years ago

  • Related to Defect #32737: Duplicate sort keys for issue query cause SQL error with SQL Server added
Actions

Also available in: Atom PDF