deecay / redmine_pivot_table

This Redmine plugin allows you to generate pivot table for issue analysis.
MIT License
52 stars 38 forks source link

invalid date #43

Open neocosmic2 opened 6 years ago

neocosmic2 commented 6 years ago

Started GET "/redmine/projects/bpsconnect-casino/pivottables" for 127.0.0.1 at 2017-11-04 17:43:30 +0800 Processing by PivottablesController#index as HTML Parameters: {"project_id"=>"bpsconnect-casino"} Current user: neo (id=1) Rendered plugins/redmine_pivot_table/app/views/pivottables/index.html.erb within layouts/base (42.1ms) Completed 500 Internal Server Error in 120ms (ActiveRecord: 23.5ms)

ActionView::Template::Error (invalid date): 57: <% if @table == "activity" %> 58: data = <%= raw parse_events(@events).to_json %>; 59: <% else %> 60: data = <%= raw parse_issues(@issues).to_json %>; 61: <% end %> 62: 63: var dateFormat = $.pivotUtilities.derivers.dateFormat; plugins/redmine_pivot_table/app/helpers/pivottables_helper.rb:68:in parse' plugins/redmine_pivot_table/app/helpers/pivottables_helper.rb:68:inblock (2 levels) in parse_issues' plugins/redmine_pivot_table/app/helpers/pivottables_helper.rb:57:in each' plugins/redmine_pivot_table/app/helpers/pivottables_helper.rb:57:inblock in parse_issues' plugins/redmine_pivot_table/app/helpers/pivottables_helper.rb:55:in each' plugins/redmine_pivot_table/app/helpers/pivottables_helper.rb:55:inparse_issues' plugins/redmine_pivot_table/app/views/pivottables/index.html.erb:60:in _plugins_redmine_pivot_table_app_views_pivottables_index_html_erb___789593742_75824952' lib/redmine/sudo_mode.rb:63:insudo_mode'

gabrielvlopes commented 6 years ago

Hi, we are using 3.4.2.stable with the same error, any idea?

Thanks

gabrielvlopes commented 6 years ago

@deecay maybe something you can take a look at? This would be greatly appreciated

rodrigocarandina commented 6 years ago

I had the same problem. To fix it I had to change the language of my user from English to Portuguese/Brazil.

deecay commented 6 years ago

Please see if this is resolved with current master. Thanks!

awk-kazmin commented 6 years ago

Hi. Does not work if the custom date format is set.

marcin295 commented 5 years ago

any idea how to fix it?

deecay commented 5 years ago

Hi @marcin295

What version of Redmine and redmine_pivot_table version do you use? Do you use custom date format? If yes, what is the setting?

marcin295 commented 5 years ago

Redmine: 3.4.2.stable redmine_pivot_table 0.0.7 date format: dd.mm.yyyy Pivot settings: Max issue count 1000

deecay commented 5 years ago

Works fine for me with that configuration and date format.

Can you paste the error output? The line numbers in the one in the original post is no longer valid.

marcin295 commented 5 years ago

Ok, i see... That is another problem with queries not with dataFormat. Sorry.

ActionView::Template::Error (undefined methodid' for nil:NilClass): 55: <% if @table == "activity" %> 56: data = <%= raw parse_events(@events).to_json %>; 57: <% else %> 58: data = <%= raw parse_issues(@issues).to_json %>; 59: <% end %> 60: 61: var dateFormat = $.pivotUtilities.derivers.dateFormat; plugins/extra_queries/lib/extra_queries/patches/helpers/queries_helper_patch.rb:19:in column_value_with_eq' app/helpers/queries_helper.rb:203:incolumn_content' plugins/a_common_libs/lib/acl/patches/helpers/queries_helper_patch.rb:13:in column_content_with_acl' plugins/redmine_pivot_table/app/helpers/pivottables_helper.rb:81:inblock (2 levels) in parse_issues' plugins/redmine_pivot_table/app/helpers/pivottables_helper.rb:78:in each' plugins/redmine_pivot_table/app/helpers/pivottables_helper.rb:78:inblock in parse_issues' plugins/redmine_pivot_table/app/helpers/pivottables_helper.rb:76:in each' plugins/redmine_pivot_table/app/helpers/pivottables_helper.rb:76:inparse_issues' plugins/redmine_pivot_table/app/views/pivottables/index.html.erb:58:in _70c30ab766d4ae71c1aca3f7cf00f766' lib/redmine/sudo_mode.rb:63:insudo_mode' `

deecay commented 5 years ago

Ok. So this is about other plugins you have (usability? a common libs?). Since I don't use those plugins, I'm afraid I cannot help.

vegaminer commented 4 years ago

Fix for pivottables_helper.rb and incorrect date error.

It's a dirty hack. I don't know if it will work for all, but in my particular case the problem was solved. Proper fix would require a "try except" (rescue) block around Date.strptime(column_content(c, i), strpformat) method call.

How did I found the solution? By adding logging.

def parse_issues(issues)
...
   myLog = Logger.new '/tmp/pt.log'
   myLog.log( Logger::DEBUG, 'strpformat: ' + strpformat )

    issues.each{|i|
      formatted_issue = {}
      @query.available_columns.each{|c|
        if ...
        elsif c.name.to_s.end_with?("_date") ||
              (c.is_a?(QueryCustomFieldColumn) && c.custom_field.field_format == "date") 
          formatted_issue[c.caption] = column_content(c, i)

          if column_content(c, i).to_s != ""
             myLog.log( Logger::DEBUG, '1: ' + c.name.to_s + ' ' +  + ' ' + column_content(c, i).to_s )
             myLog.log( Logger::DEBUG, '2: ' + Date.strptime(column_content(c, i), strpformat).to_s )
             myLog.log( Logger::DEBUG, '3: ' + Date.strptime(column_content(c, i), strpformat).strftime("%Y-W%U") )
          end

Output was

D, [2020-01-15T16:19:09.541885 #72194] DEBUG -- : strpformat: %d.%m.%Y
D, [2020-01-15T16:19:09.584536 #72194] DEBUG -- : 1: start_date  10.09.2019
D, [2020-01-15T16:19:09.584695 #72194] DEBUG -- : 2: 2019-09-10
D, [2020-01-15T16:19:09.584804 #72194] DEBUG -- : 3: 2019-W36
D, [2020-01-15T16:19:09.718327 #72194] DEBUG -- : 1: start_date  10.09.2019
D, [2020-01-15T16:19:09.718465 #72194] DEBUG -- : 2: 2019-09-10
D, [2020-01-15T16:19:09.718571 #72194] DEBUG -- : 3: 2019-W36
D, [2020-01-15T16:19:09.739822 #72194] DEBUG -- : 1: expiration_date  Expired

Note the last line. Field expiration_date (from some plugin) has value Expired in it. It's clearly not a valid date, so Date.strptime can't handle it. Quick and dirty fix is to add
c.name.to_s != 'expiration_date' to if statement:

elsif c.name.to_s != 'expiration_date' && ( c.name.to_s.end_with?("_date") ||
              (c.is_a?(QueryCustomFieldColumn) && c.custom_field.field_format == "date") )

As mentioned it's just a dirty hack, this problem should be fixed in a more appropriate way by.

ashrafalzyoud commented 2 years ago

Fix for pivottables_helper.rb and incorrect date error.

It's a dirty hack. I don't know if it will work for all, but in my particular case the problem was solved. Proper fix would require a "try except" (rescue) block around Date.strptime(column_content(c, i), strpformat) method call.

How did I found the solution? By adding logging.

def parse_issues(issues)
...
   myLog = Logger.new '/tmp/pt.log'
   myLog.log( Logger::DEBUG, 'strpformat: ' + strpformat )

    issues.each{|i|
      formatted_issue = {}
      @query.available_columns.each{|c|
        if ...
        elsif c.name.to_s.end_with?("_date") ||
              (c.is_a?(QueryCustomFieldColumn) && c.custom_field.field_format == "date") 
          formatted_issue[c.caption] = column_content(c, i)

          if column_content(c, i).to_s != ""
             myLog.log( Logger::DEBUG, '1: ' + c.name.to_s + ' ' +  + ' ' + column_content(c, i).to_s )
             myLog.log( Logger::DEBUG, '2: ' + Date.strptime(column_content(c, i), strpformat).to_s )
             myLog.log( Logger::DEBUG, '3: ' + Date.strptime(column_content(c, i), strpformat).strftime("%Y-W%U") )
          end

Output was

D, [2020-01-15T16:19:09.541885 #72194] DEBUG -- : strpformat: %d.%m.%Y
D, [2020-01-15T16:19:09.584536 #72194] DEBUG -- : 1: start_date  10.09.2019
D, [2020-01-15T16:19:09.584695 #72194] DEBUG -- : 2: 2019-09-10
D, [2020-01-15T16:19:09.584804 #72194] DEBUG -- : 3: 2019-W36
D, [2020-01-15T16:19:09.718327 #72194] DEBUG -- : 1: start_date  10.09.2019
D, [2020-01-15T16:19:09.718465 #72194] DEBUG -- : 2: 2019-09-10
D, [2020-01-15T16:19:09.718571 #72194] DEBUG -- : 3: 2019-W36
D, [2020-01-15T16:19:09.739822 #72194] DEBUG -- : 1: expiration_date  Expired

Note the last line. Field expiration_date (from some plugin) has value Expired in it. It's clearly not a valid date, so Date.strptime can't handle it. Quick and dirty fix is to add c.name.to_s != 'expiration_date' to if statement:

elsif c.name.to_s != 'expiration_date' && ( c.name.to_s.end_with?("_date") ||
              (c.is_a?(QueryCustomFieldColumn) && c.custom_field.field_format == "date") )

As mentioned it's just a dirty hack, this problem should be fixed in a more appropriate way by.

can u explain that?