Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid date #43

Open
neocosmic2 opened this issue Nov 4, 2017 · 13 comments
Open

invalid date #43

neocosmic2 opened this issue Nov 4, 2017 · 13 comments

Comments

@neocosmic2
Copy link

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:in block (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:in block 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:in parse_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:in sudo_mode'

@gabrielvlopes
Copy link

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

Thanks

@gabrielvlopes
Copy link

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

@rodrigocarandina
Copy link

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

@deecay
Copy link
Owner

deecay commented Mar 30, 2018

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

@awk-kazmin
Copy link

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

@marcin295
Copy link

any idea how to fix it?

@deecay
Copy link
Owner

deecay commented Jul 12, 2019

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
Copy link

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

@deecay
Copy link
Owner

deecay commented Jul 12, 2019

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
Copy link

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

ActionView::Template::Error (undefined method id' 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:in column_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:in block (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:in block 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:in parse_issues'
plugins/redmine_pivot_table/app/views/pivottables/index.html.erb:58:in _70c30ab766d4ae71c1aca3f7cf00f766' lib/redmine/sudo_mode.rb:63:in sudo_mode'
`

@deecay
Copy link
Owner

deecay commented Jul 12, 2019

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
Copy link

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
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants