Custom field date format in JSON API

Added by Ondrej Galbavý almost 10 years ago


I am integrating Redmine with other PHP based website via JSON API. I have problem with sending date into custom field when creating new issue. I have no idea, what date format it accepts or if it even works.

I have found this validation code in app/models/custom_field.rb:

errs << ::I18n.t('activerecord.errors.messages.not_a_date') unless value.to_s =~ /^\d{4}-\d{2}-\d{2}$/ && begin; value.to_date; rescue; false end

For example '2012-05-06', which matches that regexp, doesn't work. I have tested regexp in irb, and it doesn't work with Date class. If I do value.to_s =~ /.../, then the it passes validation. But then I get another error:

ActionView::TemplateError (undefined method `empty?' for Sun, 06 May 2012:Date) on line #10 of app/views/mailer/_issue.text.erb:
7: <%=l(:field_assigned_to)%>: <%= issue.assigned_to %>
8: <%=l(:field_category)%>: <%= issue.category %>
9: <%=l(:field_fixed_version)%>: <%= issue.fixed_version %>
10: <% issue.custom_field_values.each do |c| %><%= %>: <%= show_value(c) %>
11: <% end %>
13: <%= issue.description %>

    lib/redmine/custom_field_format.rb:94:in `format_value'
    app/helpers/custom_fields_helper.rb:123:in `format_value'
    app/helpers/custom_fields_helper.rb:115:in `show_value'
    app/views/mailer/_issue.text.erb:10:in `each'
    app/models/mailer.rb:475:in `render_multipart'
    app/models/mailer.rb:50:in `issue_add'
    app/models/issue_observer.rb:20:in `after_create'
    /usr/lib64/ruby/1.8/observer.rb:185:in `notify_observers'
    /usr/lib64/ruby/1.8/observer.rb:184:in `each'
    /usr/lib64/ruby/1.8/observer.rb:184:in `notify_observers'
    app/controllers/issues_controller.rb:162:in `create'

Not sure what now... Implement empty? for Date class and see what's next error? Am I doing something wrong? Adding issue through web interface works.

I am using redmine 1.4.3 with some minor not related modifications.


I can create new issue with filled Date custom field with this:

  <?xml version="1.0"?>
  <custom_fields type="array">
    <custom_field id="17">

Replies (1)

RE: Custom field date format in JSON API - Added by Cheyenne Wills over 9 years ago

I've run into the exact same problem. Upgraded from Redmine 1.3.2 to Redmine 1.4.5 and some of our scripts died because they errored out on a custom date field.

I created a real ugly patch to fix it, I removed the regular expression test in app/models/custom_field.rb just as you did, but I also added a little bit of code to lib/redmine/custom_field_format.rb to test to see if the format type is 'date' before doing the ?empty test.

I'm going to report this as a bug.