Defect #27153

Custom query breaks calendar view with error 500

Added by Bernhard Rohloff 14 days ago. Updated 8 days ago.

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

0%

Category:Calendar
Target version:3.4.4
Resolution: Affected version:3.4.2

Description

When the custom query includes a second sort criteria the calendar view breaks with an error 500.

Steps to reproduction:

  1. Create a custom query with a second sort criteria
  2. Select the custom query in the calendar view

This results into:

!Screenshot-2017-10-10 500 - Redmine.png!

Screenshot-2017-10-10 500 - Redmine.png (13.7 KB) Bernhard Rohloff, 2017-10-10 10:43

calendar_error500_production_trunk.log (3.95 KB) Bernhard Rohloff, 2017-10-10 15:48

calendar_error500_production_bitnami.log (4.63 KB) Bernhard Rohloff, 2017-10-10 15:48

calendars_order_error_500_quick.diff Magnifier - Workaround like in r3379 for sort_criteria (557 Bytes) Bernhard Rohloff, 2017-10-12 10:50

calendars_order_error_500_cleanup.diff Magnifier - Removes confusing workarounds in the controllers. (2.13 KB) Bernhard Rohloff, 2017-10-12 10:50

tests_for_custom_query_breaks_calendar_view.patch Magnifier (1.1 KB) Marius BALTEANU, 2017-10-16 00:12


Related issues

Duplicated by Redmine - Defect #26544: SQL-Error occurs sometimes when clicking on "calendar" tab Closed

History

#1 Updated by Toshi MARUYAMA 14 days ago

  • Status changed from New to Needs feedback

Please see submissions.

#2 Updated by Bernhard Rohloff 13 days ago

Sorry for the useless screenshot. It's obvious that this error message was worth nothing...

I've experienced this issue on three separate Redmine instances.
A Bitnami VM V3.4.2 a manual installation with V3.4.2 and a development installation (trunk r16970).
You can find the production logs for the Bitnami VM and the trunk installation in the attachments.

Bitnami Environment:

Environment:
  Redmine version                3.4.2.stable
  Ruby version                   2.3.4-p301 (2017-03-30) [x86_64-linux]
  Rails version                  4.2.8
  Environment                    production
  Database adapter               Mysql2
SCM:
  Subversion                     1.9.7
  Cvs                            1.12.13
  Filesystem                     
Redmine plugins:
  clipboard_image_paste          1.12
  redmine_custom_macros          0.0.1
  redmine_lightbox2              0.4.3

Trunk Installation:

Environment:
  Redmine version                3.4.2.devel.16970
  Ruby version                   2.2.7-p470 (2017-03-28) [x86_64-linux]
  Rails version                  5.1.2
  Environment                    production
  Database adapter               Mysql2
SCM:
  Subversion                     1.6.11
  Mercurial                      2.2.2
  Bazaar                         2.1.1
  Git                            2.7.4
  Filesystem                     
Redmine plugins:
  no plugin installed

#3 Updated by Marius BALTEANU 13 days ago

The same error was reported in #26544.

#4 Updated by Bernhard Rohloff 13 days ago

Yes, this seems to be the same error.
On all my installations it is 100% reproducible.

These cases I've tested right now:
Standard view (no filters) --> works
Custom query (standard view) with single sort criteria --> works
Custom query (standard view) with second sort criteria --> fails

MySQL Versions
Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1 (trunk version)
Ver 14.14 Distrib 5.6.37, for linux-glibc2.12 (x86_64) using EditLine wrapper (Bitnami V3.4.2.stable)

#5 Updated by Go MAEDA 12 days ago

  • Status changed from Needs feedback to Confirmed
  • Target version set to 3.4.3

I confirmed the problem. 3.4-stable and trunk are affected by the problem. No problem in 3.3-stable.

According to the result of `git bisect`, r16390 caused the problem.

#6 Updated by Bernhard Rohloff 12 days ago

That's right. r16390 is the bad revisison. I wrote my debugging results in #26544#note-28, yesterday. The issue seems to be a duplicate and there are more guys affected by this in #26544. I also wrote two possible workarounds there, but until now, there isn't any feedback on it. Because there are two slightly different ways to fix this, I'm a bit double-minded for which solution I should create a patch.

#7 Updated by Marius BALTEANU 12 days ago

  • Duplicated by Defect #26544: SQL-Error occurs sometimes when clicking on "calendar" tab added

#8 Updated by Bernhard Rohloff 12 days ago

I've made a patch with the second solution of my fixing proposals in #26544#note-28. Although it's not my prefered solution, it fits more to the workaround JP made in r3379.

To fix it in a cleaner way, you would have to modify the issues method in app/models/issue_query.rb which could break other modules (Gantt) and I have no clue how the method is intended to work.

# Returns the issues ids
# Valid options are :order, :offset, :limit, :include, :conditions
def issue_ids(options={})
  order_option = [group_by_sort_order, (options[:order] || sort_clause)].flatten.reject(&:blank?)

   scope = Issue.visible.
  ...

To make the choice of order (query or options) explicit would make more sense to me.
In this case we could remove the ugly workarounds in app/controllers/calendards_controller.rb and app/controllers/gantts_controller.rb (where it works already, because there are :order options).

  # Returns the issues
  # Valid options are :order, :offset, :limit, :include, :conditions
  def issues(options={})
    order_option = ([options[:order]] || [group_by_sort_order, sort_clause]).flatten.reject(&:blank?)

    scope = Issue.visible.
   ...

I've attached both patches, so you can choose which fits best.
Cheers!

PS: As far as I was able to test it, Gantt also seems to work well, with the "cleanup" patch.

#9 Updated by Jean-Philippe Lang 9 days ago

  • Target version changed from 3.4.3 to 3.4.4

Can we add a failing test in the patch?

#10 Updated by Marius BALTEANU 8 days ago

Jean-Philippe Lang wrote:

Can we add a failing test in the patch?

Here is a patch with two failing tests.

Also available in: Atom PDF